Skip to content

Commit 9bb269c

Browse files
committed
chore: require PHP 8.2, adopt Mago for quality checks, and refactor codebase
1 parent 9f0c184 commit 9bb269c

23 files changed

Lines changed: 704 additions & 430 deletions

.github/workflows/check.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
strategy:
2424
fail-fast: false
2525
matrix:
26-
php-version: ["8.1", "8.2", "8.3", "8.4", "8.5"]
26+
php-version: ["8.2", "8.3", "8.4", "8.5"]
2727
experimental: [false]
2828
os: [ubuntu-latest]
2929
coverage-extension: [pcov]
@@ -46,6 +46,8 @@ jobs:
4646
path: ~/.composer/cache/
4747
key: composer-cache
4848
- name: Install dependencies
49+
env:
50+
GH_TOKEN: ${{ github.token }}
4951
run: make deps
5052
- name: Run all tests
5153
run: make qa

CONTRIBUTING.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Please follow the [Security Policy](SECURITY.md) and report them privately.
4040

4141
### Requirements
4242

43-
- PHP **≥ 8.1**
43+
- PHP **≥ 8.2**
4444
- [Composer](https://getcomposer.org/) v2
4545
- `make`, `git`
4646
- Optional: `rpmbuild` (RPM packaging), `dpkg-buildpackage` (DEB packaging)
@@ -120,8 +120,8 @@ The `Makefile` exposes all common development tasks:
120120
|---------|-------------|
121121
| `make qa` | Run linting, static analysis, tests, and reports |
122122
| `make test` | Run PHPUnit with code coverage |
123-
| `make lint` | Check coding standards (PHPCS, PHPMD, PHPStan) |
124-
| `make codefix` | Auto-fix coding standard violations (PHPCBF) |
123+
| `make lint` | Check coding standards |
124+
| `make format` | Auto-format the code |
125125
| `make buildall` | Install dependencies, fix style, run QA, and build packages |
126126
| `make clean` | Remove `vendor/` and `target/` directories |
127127
| `make server` | Start the built-in PHP development server for the examples |
@@ -133,8 +133,8 @@ Run `make help` to see the full list of available targets.
133133
## Coding Standards
134134

135135
- The codebase follows **PSR-12** for formatting.
136-
- Run `make codefix` to auto-fix style violations before committing.
137-
- Run `make lint` to catch remaining issues (PHPCS, PHPMD, PHPStan).
136+
- Run `make format` to auto-format the code.
137+
- Run `make lint` to catch remaining issues.
138138
- All source files live under `src/`, all tests under `test/`.
139139
- Use strict types and explicit visibility on all class members.
140140
- Avoid introducing new external dependencies without prior discussion.

Makefile

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,6 @@ COMPOSER=$(PHP) -d "apc.enable_cli=0" $(shell which composer)
9292
# phpDocumentor executable file
9393
PHPDOC=$(shell which phpDocumentor)
9494

95-
# phpstan version
96-
PHPSTANVER=2.1.40
97-
9895
# --- MAKE TARGETS ---
9996

10097
# Display general help about this command
@@ -120,7 +117,7 @@ x: buildall
120117

121118
## Full build and test sequence
122119
.PHONY: buildall
123-
buildall: deps codefix qa bz2 rpm deb
120+
buildall: deps format qa bz2 rpm deb
124121

125122
## Package the library in a compressed bz2 archive
126123
.PHONY: bz2
@@ -134,11 +131,6 @@ bz2:
134131
clean:
135132
rm -rf ./vendor $(TARGETDIR)
136133

137-
## Fix code style violations
138-
.PHONY: codefix
139-
codefix:
140-
./vendor/bin/phpcbf --ignore="\./vendor/" --standard=psr12 src test
141-
142134
## Build a DEB package for Debian-like Linux distributions
143135
.PHONY: deb
144136
deb:
@@ -171,8 +163,7 @@ endif
171163
deps: ensuretarget
172164
rm -rf ./vendor/*
173165
($(COMPOSER) install -vvv --no-interaction)
174-
curl --silent --show-error --fail --location --output ./vendor/phpstan.phar https://github.com/phpstan/phpstan/releases/download/${PHPSTANVER}/phpstan.phar \
175-
&& chmod +x ./vendor/phpstan.phar
166+
curl --proto '=https' --tlsv1.2 --silent --show-error --fail --location https://carthage.software/mago.sh | bash -s -- --install-dir=./vendor/bin
176167

177168
## Generate source code documentation
178169
.PHONY: doc
@@ -209,13 +200,18 @@ ifneq ($(strip $(CONFIGPATH)),)
209200
find $(PATHINSTCFG) -type f -exec chmod 644 {} \;
210201
endif
211202

212-
## Test source code for coding standard violations
203+
## Format the source code
204+
.PHONY: format
205+
format:
206+
./vendor/bin/mago fmt src test
207+
208+
## Analyze and Lint the source code
213209
.PHONY: lint
214210
lint:
215-
./vendor/bin/phpcs --standard=phpcs.xml
216-
./vendor/bin/phpmd src text codesize,unusedcode,naming,design --exclude */vendor/*
217-
./vendor/bin/phpmd test text unusedcode,naming,design --exclude */vendor/*
218-
php -r 'exit((int)version_compare(PHP_MAJOR_VERSION, "7", ">"));' || ./vendor/phpstan.phar analyse
211+
./vendor/bin/mago --config ./mago.src.toml analyze src
212+
./vendor/bin/mago --config ./mago.test.toml analyze test
213+
./vendor/bin/mago --config ./mago.src.toml lint src
214+
./vendor/bin/mago --config ./mago.test.toml lint test
219215

220216
## Run all tests and reports
221217
.PHONY: qa

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ The parser is designed for tooling scenarios such as content inspection, metadat
4646

4747
## Requirements
4848

49-
- PHP 8.1 or later
49+
- PHP 8.2 or later
5050
- Extension: `pcre`
5151
- Composer
5252

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.1.2
1+
3.2.0

composer.json

Lines changed: 60 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,63 @@
11
{
2-
"name": "tecnickcom/tc-lib-pdf-parser",
3-
"description": "PHP library to parse PDF documents",
4-
"type": "library",
5-
"homepage": "https://tcpdf.org",
6-
"license": "LGPL-3.0-or-later",
7-
"keywords": [
8-
"tc-lib-pdf-parser",
9-
"PDF",
10-
"parser",
11-
"document"
12-
],
13-
"authors": [
14-
{
15-
"name": "Nicola Asuni",
16-
"email": "info@tecnick.com",
17-
"role": "lead"
2+
"name": "tecnickcom/tc-lib-pdf-parser",
3+
"description": "PHP library to parse PDF documents",
4+
"type": "library",
5+
"homepage": "https://tcpdf.org",
6+
"license": "LGPL-3.0-or-later",
7+
"keywords": [
8+
"tc-lib-pdf-parser",
9+
"PDF",
10+
"parser",
11+
"document"
12+
],
13+
"authors": [
14+
{
15+
"name": "Nicola Asuni",
16+
"email": "info@tecnick.com",
17+
"role": "lead"
18+
}
19+
],
20+
"funding": [
21+
{
22+
"type": "github",
23+
"url": "https://github.com/sponsors/tecnickcom"
24+
}
25+
],
26+
"require": {
27+
"php": ">=8.2",
28+
"ext-pcre": "*",
29+
"tecnickcom/tc-lib-pdf-filter": "^2.2"
30+
},
31+
"minimum-stability": "dev",
32+
"prefer-stable": true,
33+
"config": {
34+
"allow-plugins": {
35+
"dealerdirect/phpcodesniffer-composer-installer": true
36+
}
37+
},
38+
"require-dev": {
39+
"pdepend/pdepend": "^2.16",
40+
"phpunit/phpunit": "^13.1 || ^12.5 || ^11.5",
41+
"phpcompatibility/php-compatibility": "^10.0.0@dev"
42+
},
43+
"autoload": {
44+
"psr-4": {
45+
"Com\\Tecnick\\Pdf\\Parser\\": "src"
46+
}
47+
},
48+
"autoload-dev": {
49+
"psr-4": {
50+
"Test\\": "test"
51+
}
52+
},
53+
"support": {
54+
"issues": "https://github.com/tecnickcom/tc-lib-pdf-parser/issues",
55+
"source": "https://github.com/tecnickcom/tc-lib-pdf-parser"
56+
},
57+
"scripts": {
58+
"test": "XDEBUG_MODE=coverage ./vendor/bin/phpunit --stderr test",
59+
"cs-check": "./vendor/bin/mago --config ./mago.src.toml lint src && ./vendor/bin/mago --config ./mago.test.toml lint test",
60+
"cs-fix": "./vendor/bin/mago fmt src test",
61+
"analyse": "./vendor/bin/mago --config ./mago.src.toml analyze src && ./vendor/bin/mago --config ./mago.test.toml analyze test"
1862
}
19-
],
20-
"funding": [
21-
{
22-
"type": "github",
23-
"url": "https://github.com/sponsors/tecnickcom"
24-
}
25-
],
26-
"require": {
27-
"php": ">=8.1",
28-
"ext-pcre": "*",
29-
"tecnickcom/tc-lib-pdf-filter": "^2.1"
30-
},
31-
"minimum-stability": "dev",
32-
"prefer-stable": true,
33-
"config": {
34-
"allow-plugins": {
35-
"dealerdirect/phpcodesniffer-composer-installer": true
36-
}
37-
},
38-
"require-dev": {
39-
"pdepend/pdepend": "^2.16",
40-
"phpmd/phpmd": "^2.15",
41-
"phpunit/phpunit": "^13.1 || ^12.5 || ^11.5 || ^10.5",
42-
"squizlabs/php_codesniffer": "^4.0",
43-
"phpcompatibility/php-compatibility": "^10.0.0@dev"
44-
},
45-
"autoload": {
46-
"psr-4": {
47-
"Com\\Tecnick\\Pdf\\Parser\\": "src"
48-
}
49-
},
50-
"autoload-dev": {
51-
"psr-4": { "Test\\": "test" }
52-
},
53-
"support": {
54-
"issues": "https://github.com/tecnickcom/tc-lib-pdf-parser/issues",
55-
"source": "https://github.com/tecnickcom/tc-lib-pdf-parser"
56-
},
57-
"scripts": {
58-
"test": "XDEBUG_MODE=coverage ./vendor/bin/phpunit --stderr test",
59-
"cs-check": "./vendor/bin/phpcs --standard=phpcs.xml",
60-
"cs-fix": "./vendor/bin/phpcbf --ignore=\"./vendor/\" --standard=psr12 src test",
61-
"analyse": "./vendor/phpstan.phar analyse"
62-
}
6363
}

mago.src.toml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#:schema https://mago.carthage.software/1.26.0/schema.json
2+
version = "1"
3+
php-version = "8.2.0"
4+
5+
[source]
6+
workspace = "."
7+
paths = ["src"]
8+
includes = ["vendor"]
9+
excludes = []
10+
11+
[source.glob]
12+
literal-separator = true
13+
14+
[formatter]
15+
print-width = 120
16+
tab-width = 4
17+
use-tabs = false
18+
19+
[linter]
20+
integrations = []
21+
22+
[linter.rules]
23+
ambiguous-function-call = { enabled = false }
24+
literal-named-argument = { enabled = false }
25+
cyclomatic-complexity = { enabled = false }
26+
excessive-parameter-list = { enabled = true }
27+
halstead = { enabled = true, effort-threshold = 12000, difficulty-threshold = 80 }
28+
identity-comparison = { enabled = true }
29+
kan-defect = { enabled = false }
30+
no-boolean-flag-parameter = { enabled = false }
31+
no-else-clause = { enabled = false }
32+
no-empty = { enabled = true }
33+
too-many-methods = { enabled = false }
34+
no-isset = { enabled = true, allow-array-checks = true }
35+
36+
[analyzer]
37+
plugins = []
38+
ignore = [
39+
{ code = "string-member-selector", in = ["src/Process/RawObject.php"] },
40+
{ code = "imprecise-type", in = ["src/Process/RawObject.php"] },
41+
]
42+
find-unused-definitions = true
43+
find-unused-expressions = true
44+
analyze-dead-code = true
45+
memoize-properties = true
46+
check-throws = true
47+
unchecked-exceptions = [
48+
"Error",
49+
"LogicException",
50+
"ReflectionException",
51+
]
52+
unchecked-exception-classes = []
53+
check-missing-override = true
54+
find-unused-parameters = true
55+
strict-list-index-checks = true
56+
strict-array-index-existence = true
57+
allow-array-truthy-operand = false
58+
no-boolean-literal-comparison = true
59+
check-missing-type-hints = true
60+
register-super-globals = true

mago.test.toml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#:schema https://mago.carthage.software/1.26.0/schema.json
2+
version = "1"
3+
php-version = "8.2.0"
4+
5+
[source]
6+
workspace = "."
7+
paths = ["src", "test"]
8+
includes = ["vendor"]
9+
excludes = []
10+
11+
[source.glob]
12+
literal-separator = true
13+
14+
[formatter]
15+
print-width = 120
16+
tab-width = 4
17+
use-tabs = false
18+
19+
[linter]
20+
integrations = ["phpunit"]
21+
22+
[linter.rules]
23+
ambiguous-function-call = { enabled = false }
24+
literal-named-argument = { enabled = false }
25+
assertion-style = { enabled = false }
26+
cyclomatic-complexity = { enabled = false }
27+
excessive-parameter-list = { enabled = false }
28+
halstead = { enabled = false, effort-threshold = 7000 }
29+
identity-comparison = { enabled = false }
30+
kan-defect = { enabled = false }
31+
no-boolean-flag-parameter = { enabled = false }
32+
no-else-clause = { enabled = false }
33+
no-empty = { enabled = false }
34+
no-empty-catch-clause = { enabled = false }
35+
no-isset = { enabled = false }
36+
readable-literal = { enabled = false }
37+
str-contains = { enabled = false }
38+
strict-assertions = { enabled = false }
39+
strict-behavior = { enabled = false }
40+
strict-types = { enabled = false }
41+
too-many-methods = { enabled = false }
42+
43+
[analyzer]
44+
plugins = []
45+
find-unused-definitions = true
46+
find-unused-expressions = true
47+
analyze-dead-code = true
48+
memoize-properties = true
49+
check-throws = true
50+
unchecked-exceptions = [
51+
"Error",
52+
"LogicException",
53+
"ReflectionException",
54+
"PHPUnit\\Framework\\Exception",
55+
"PHPUnit\\Framework\\ExpectationFailedException",
56+
"PHPUnit\\Framework\\UnknownClassOrInterfaceException",
57+
]
58+
unchecked-exception-classes = []
59+
check-missing-override = true
60+
find-unused-parameters = true
61+
strict-list-index-checks = true
62+
strict-array-index-existence = true
63+
allow-array-truthy-operand = false
64+
no-boolean-literal-comparison = true
65+
check-missing-type-hints = true
66+
register-super-globals = true

phpcs.xml

Lines changed: 0 additions & 10 deletions
This file was deleted.

phpstan.neon

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)