Skip to content

Commit 5fefa8a

Browse files
authored
Add Rector, update tooling, update code style. (#185)
1 parent 9431ab6 commit 5fefa8a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+2686
-1179
lines changed

.github/workflows/ci.yaml

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,8 @@ jobs:
1111
VUFIND_LOCAL_DIR: $GITHUB_WORKSPACE/local
1212
strategy:
1313
matrix:
14-
php-version: ['8.1', '8.2', '8.3', '8.4', '8.4-no-mongo']
14+
php-version: ['8.2', '8.3', '8.4', '8.4-no-mongo']
1515
include:
16-
- php-version: 8.1
17-
phing_tasks: "qa-tasks"
18-
php-extensions: intl, xsl, mongodb
1916
- php-version: 8.2
2017
phing_tasks: "qa-tasks"
2118
php-extensions: intl, xsl, mongodb
@@ -64,6 +61,20 @@ jobs:
6461
key: "php-${{ matrix.php-version }}-phpstan-${{ github.sha }}"
6562
restore-keys: "php-${{ matrix.php-version }}-phpstan-"
6663

64+
- name: Cache PHP_CodeSniffer data
65+
uses: actions/cache@v4
66+
with:
67+
path: tests/phpcs.cache.json
68+
key: "php-${{ matrix.php-version }}-phpcs-${{ github.sha }}"
69+
restore-keys: "php-${{ matrix.php-version }}-phpcs-"
70+
71+
- name: Cache rector data
72+
uses: actions/cache@v4
73+
with:
74+
path: .rector
75+
key: "php-${{ matrix.php-version }}-rector-${{ github.sha }}"
76+
restore-keys: "php-${{ matrix.php-version }}-rector-"
77+
6778
- name: Install composer dependencies
6879
run: composer install
6980

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ conf/*.lst
2020
.php_cs_cache
2121
.psalm_cache
2222
.phpstan_cache
23+
.rector
2324
*.log
2425
mappings/*.map
2526
mappings/*.php
@@ -29,4 +30,4 @@ transformations/*.xsl
2930
vendor
3031
tests/.phpunit.cache
3132
tests/.phpunit.result.cache
32-
33+
tests/phpcs.cache.json

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## 3.0.0 - TBD
99

10-
**N.B. This version bumps the minimum PHP version to 8.1**
10+
**N.B. This version bumps the minimum PHP version to 8.2**
1111

1212
Anything marked with [**BC**] is known to affect backward compatibility with previous versions.
1313

build.xml

Lines changed: 64 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
<property name="tmp" value="/tmp" />
44
<property name="package" value="${phing.project.name}" override="true" />
55
<property name="builddir" value="${tmp}/build/${phing.project.name}" override="true" />
6-
<property name="basedir" value="${project.basedir}" override="true" />
7-
<property name="srcdir" value="${basedir}/src/RecordManager" override="true" />
6+
<property name="srcdir" value="${project.basedir}" override="true" />
87
<property name="phpunit_extra_params" value="" />
98

109
<!-- Main Target -->
@@ -19,10 +18,13 @@
1918
<phingcall target="php-cs-fixer-dryrun"/>
2019
<phingcall target="psalm"/>
2120
<phingcall target="phpstan-console"/>
21+
<phingcall target="rector-console"/>
2222
</target>
2323

2424
<!-- Fix PHP Tasks -->
2525
<target name="fix-php" description="quality assurance php tasks">
26+
<!-- Rector may introduce style issues, so run it first -->
27+
<phingcall target="rector"/>
2628
<phingcall target="php-cs-fixer"/>
2729
<phingcall target="phpcbf"/>
2830
</target>
@@ -41,67 +43,110 @@
4143
<mkdir dir="${builddir}/reports/coverage"/>
4244
</then>
4345
</if>
44-
<exec executable="${basedir}/vendor/bin/phpunit" passthru="true" checkreturn="true">
45-
<arg line="-c ${basedir}/tests/phpunit.xml --display-deprecations --coverage-clover ${builddir}/reports/coverage/clover.xml --coverage-html ${builddir}/reports/coverage/ ${basedir}/tests ${phpunit_extra_params}" />
46+
<exec executable="${srcdir}/vendor/bin/phpunit" passthru="true" checkreturn="true">
47+
<arg line="-c ${srcdir}/tests/phpunit.xml --display-all-issues --coverage-clover ${builddir}/reports/coverage/clover.xml --coverage-html ${builddir}/reports/coverage/ ${srcdir}/tests ${phpunit_extra_params}" />
4648
<env name="XDEBUG_MODE" value="coverage" />
4749
</exec>
4850
</target>
4951
<target name="phpunitfast" description="Run tests">
50-
<exec executable="${basedir}/vendor/bin/phpunit" passthru="true" checkreturn="true" >
51-
<arg line="-c ${basedir}/tests/phpunit.xml --display-deprecations ${basedir}/tests ${phpunit_extra_params}" />
52+
<exec executable="${srcdir}/vendor/bin/phpunit" passthru="true" checkreturn="true" >
53+
<arg line="-c ${srcdir}/tests/phpunit.xml --display-all-issues ${srcdir}/tests ${phpunit_extra_params}" />
5254
</exec>
5355
</target>
5456

5557
<!-- PHP CodeSniffer -->
5658
<target name="phpcbf">
57-
<exec executable="${basedir}/vendor/bin/phpcbf" escape="false" passthru="true" checkreturn="true">
58-
<arg line="--standard=${basedir}/tests/phpcs.xml" />
59+
<!-- Run phpcs first to find any problems (faster than phpcbf): -->
60+
<exec executable="${srcdir}/vendor/bin/phpcs" escape="false" returnProperty="phpcs_retval" outputProperty="phpcs_output">
61+
<arg line="--cache=${srcdir}/tests/phpcs.cache.json --standard=${srcdir}/tests/phpcs.xml" />
62+
</exec>
63+
<if>
64+
<not><equals arg1="${phpcs_retval}" arg2="0" /></not>
65+
<then>
66+
<echo msg="Trying to fix the following issues: " />
67+
<echo msg="${phpcs_output}" />
68+
<!-- Extract file names from phpcs output: -->
69+
<property name="phpcbf_filelist" value="${phpcs_output}">
70+
<filterchain>
71+
<linecontainsregexp>
72+
<regexp pattern="^FILE: (.*)" />
73+
</linecontainsregexp>
74+
<striplinebreaks />
75+
<replaceregexp>
76+
<regexp pattern="FILE: " replace=" " />
77+
</replaceregexp>
78+
</filterchain>
79+
</property>
80+
<!-- Finally, run phpcbf: -->
81+
<exec executable="${srcdir}/vendor/bin/phpcbf" escape="false" passthru="true">
82+
<arg line="--standard=${srcdir}/tests/phpcs.xml ${phpcbf_filelist}" />
83+
</exec>
84+
</then>
85+
</if>
86+
</target>
87+
88+
89+
<target name="phpcbf">
90+
<exec executable="${srcdir}/vendor/bin/phpcbf" escape="false" passthru="true" checkreturn="true">
91+
<arg line="--standard=${srcdir}/tests/phpcs.xml" />
5992
</exec>
6093
</target>
6194
<target name="phpcs">
62-
<exec executable="${basedir}/vendor/bin/phpcs" escape="false" passthru="true" checkreturn="true">
63-
<arg line="-s --standard=${basedir}/tests/phpcs.xml" />
95+
<exec executable="${srcdir}/vendor/bin/phpcs" escape="false" passthru="true" checkreturn="true">
96+
<arg line="-s --standard=${srcdir}/tests/phpcs.xml" />
6497
</exec>
6598
</target>
6699

67100
<!-- php-cs-fixer (first task applies fixes, second task simply checks if they are needed) -->
68101
<target name="php-cs-fixer">
69-
<exec executable="${basedir}/vendor/bin/php-cs-fixer" passthru="true" escape="false">
70-
<arg line="fix --config=${basedir}/tests/recordmanager.php-cs-fixer.php -vvv" />
102+
<exec executable="${srcdir}/vendor/bin/php-cs-fixer" passthru="true" escape="false">
103+
<arg line="fix --config=${srcdir}/tests/recordmanager.php-cs-fixer.php -vvv" />
71104
</exec>
72105
</target>
73106
<target name="php-cs-fixer-dryrun">
74-
<exec executable="${basedir}/vendor/bin/php-cs-fixer" passthru="true" escape="false" checkreturn="true">
75-
<arg line="fix --config=${basedir}/tests/recordmanager.php-cs-fixer.php --dry-run -vvv --diff" />
107+
<exec executable="${srcdir}/vendor/bin/php-cs-fixer" passthru="true" escape="false" checkreturn="true">
108+
<arg line="fix --config=${srcdir}/tests/recordmanager.php-cs-fixer.php --dry-run -vvv --diff" />
109+
</exec>
110+
</target>
111+
112+
<!-- Rector -->
113+
<target name="rector-console">
114+
<exec executable="${srcdir}/vendor/bin/rector" escape="false" passthru="true" checkreturn="true">
115+
<arg line="--config=${srcdir}/tests/rector.php --dry-run" />
116+
</exec>
117+
</target>
118+
<target name="rector">
119+
<exec executable="${srcdir}/vendor/bin/rector" escape="false" passthru="true" checkreturn="true">
120+
<arg line="--config=${srcdir}/tests/rector.php" />
76121
</exec>
77122
</target>
78123

79124
<!-- Report rule violations with PHPMD (mess detector) -->
80125
<target name="phpmd">
81126
<echo>Make sure you have phpmd installed in path. It's not installed by default due to its dependencies.</echo>
82127
<exec executable="phpmd">
83-
<arg line="${srcdir} html ${basedir}/tests/phpmd.xml --reportfile ${basedir}/reports/phpmd.html" />
128+
<arg line="${srcdir}/src html ${srcdir}/tests/phpmd.xml --reportfile ${srcdir}/reports/phpmd.html" />
84129
</exec>
85130
</target>
86131

87132
<!-- Psalm -->
88133
<target name="psalm">
89-
<exec executable="${basedir}/vendor/bin/psalm" escape="false" passthru="true" checkreturn="true">
134+
<exec executable="${srcdir}/vendor/bin/psalm" escape="false" passthru="true" checkreturn="true">
90135
<!-- threads=1 is a workaround for "Fatal error: Maximum execution time of 0 seconds exceeded" with macOS-->
91136
<arg line="--threads=1 --diff" />
92137
</exec>
93138
</target>
94139
<target name="psalm-info">
95-
<exec executable="${basedir}/vendor/bin/psalm" escape="false" passthru="true" checkreturn="true">
140+
<exec executable="${srcdir}/vendor/bin/psalm" escape="false" passthru="true" checkreturn="true">
96141
<!-- threads=1 is a workaround for "Fatal error: Maximum execution time of 0 seconds exceeded" with macOS-->
97142
<arg line="--threads=1 --diff --show-info=true" />
98143
</exec>
99144
</target>
100145

101146
<!-- Phpstan -->
102147
<target name="phpstan-console">
103-
<exec executable="${basedir}/vendor/bin/phpstan.phar" escape="false" passthru="true" checkreturn="true">
104-
<arg line="--configuration=${basedir}/tests/phpstan.neon --memory-limit=2G analyse" />
148+
<exec executable="${srcdir}/vendor/bin/phpstan.phar" escape="false" passthru="true" checkreturn="true">
149+
<arg line="--configuration=${srcdir}/tests/phpstan.neon --memory-limit=2G analyse" />
105150
</exec>
106151
</target>
107152
</project>

composer.json

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"license": "GPL-2.0",
1111
"config": {
1212
"platform": {
13-
"php": "8.1"
13+
"php": "8.2.4"
1414
},
1515
"allow-plugins": {
1616
"composer/package-versions-deprecated": true,
@@ -31,30 +31,32 @@
3131
"ext-mongodb": "*"
3232
},
3333
"require": {
34+
"php": ">=8.2.4",
3435
"cash/lrucache": "1.0.0",
35-
"guzzlehttp/guzzle": "^7.8",
36+
"guzzlehttp/guzzle": "7.10.0",
3637
"laminas/laminas-mvc": "3.8.0",
37-
"laminas/laminas-router": "3.14.0",
38+
"laminas/laminas-router": "3.16.0",
3839
"laminas/laminas-servicemanager": "3.23.0",
3940
"laminas/laminas-xml": "1.7.0",
4041
"league/mime-type-detection": "1.16.0",
4142
"ml/json-ld": "1.2.1",
42-
"mongodb/mongodb": "1.20.0",
43-
"pcrov/jsonreader": "1.0.3",
43+
"mongodb/mongodb": "2.1.2",
44+
"pcrov/jsonreader": "1.0.4",
4445
"phayes/geophp": "1.2",
4546
"pietercolpaert/hardf": "0.5.0",
46-
"symfony/console": "6.4.15",
47-
"symfony/lock": "6.4.13",
48-
"vufind-org/vufind-marc": "1.1.0",
47+
"symfony/console": "6.4.25",
48+
"symfony/lock": "6.4.26",
49+
"vufind-org/vufind-marc": "1.2.0",
4950
"wikimedia/composer-merge-plugin": "2.1.0"
5051
},
5152
"require-dev": {
52-
"friendsofphp/php-cs-fixer": "3.65.0",
53-
"phing/phing": "3.0.1",
54-
"phpstan/phpstan": "1.12.12",
55-
"phpunit/phpunit": "10.5.38",
56-
"squizlabs/php_codesniffer": "3.11.1",
57-
"vimeo/psalm": "5.26.1"
53+
"friendsofphp/php-cs-fixer": "3.89.2",
54+
"phing/phing": "3.1.0",
55+
"phpstan/phpstan": "2.1.32",
56+
"phpunit/phpunit": "11.5.43",
57+
"rector/rector": "2.2.7",
58+
"squizlabs/php_codesniffer": "4.0.1",
59+
"vimeo/psalm": "6.5.0"
5860
},
5961
"scripts": {
6062
"fix": "phing fix-php",

0 commit comments

Comments
 (0)