Skip to content

Commit bea25ea

Browse files
PDowneyclaude
andcommitted
Write the PHP in PHP 8 forms, simplify uninstall errors, add Rector
- Apply Rector's PHP 8 rules: short arrays, an arrow function, and first-class callables; add rector.php and a Rector CI job - Raise the uninstall's failures through one helper; the behavior and messages are unchanged - Deprecate es_optimizer_clear_options_cache(), which does nothing - Require short arrays; override smol-toml and katex for their advisories - Remove three unused issue templates Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent e5a9af7 commit bea25ea

21 files changed

Lines changed: 318 additions & 251 deletions

‎.distignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
/phpstan.neon
7070
/phpunit.xml
7171
/psalm.xml
72+
/rector.php
7273
/renovate.json
7374
/stubs
7475
/tests

‎.gitattributes‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
/phpunit.xml export-ignore
2424
/psalm.xml export-ignore
2525
/README.md export-ignore
26+
/rector.php export-ignore
2627
/renovate.json export-ignore
2728
/SECURITY.md export-ignore
2829
/stubs export-ignore

‎.github/ISSUE_TEMPLATE/compatibility-test-failure.md‎

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

‎.github/ISSUE_TEMPLATE/phpunit-failure.md‎

Lines changed: 0 additions & 44 deletions
This file was deleted.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
name: "Rector Failure"
3+
about: "Automated issue created when the Rector dry run finds dated code"
4+
title: "Rector Dry Run Failed - PHP {{ env.PHP_VERSION }}"
5+
labels: ["bug", "rector", "static-analysis", "automated"]
6+
assignees: []
7+
---
8+
9+
## Rector Dry Run Failure
10+
11+
The Rector job failed. Inspect the failure stage before attributing the failure to the code.
12+
13+
**Failure stage:** `{{ env.FAILURE_STAGE }}`
14+
15+
**PHP Version:** {{ env.PHP_VERSION }}
16+
**Workflow Run:** [{{ env.RUN_ID }}]({{ env.WORKFLOW_URL }})
17+
**Date:** {{ date | date('YYYY-MM-DD') }}
18+
19+
### What the job runs
20+
21+
`composer rector` runs `rector process --dry-run` with `rector.php`. It changes nothing, and it fails when any configured rule would change the plugin's PHP: the PHP 8.2 sets, and the dead-code, code-quality, type-declaration, and early-return sets, without the rules that `rector.php` skips for WordPress.
22+
23+
### Next Steps
24+
25+
1. Read the diff in the job log: it shows each change Rector would make, and the rule that makes it.
26+
2. Run `composer rector` locally to see the same diff, then `vendor/bin/rector process` to apply it, and `composer phpcs:fix` to restore the WordPress formatting.
27+
3. Run `composer check-all`. If a change breaks a test or a coding-standard rule, add that rule to the skip list in `rector.php`, with a comment that says why, instead of keeping the change.
28+
4. Re-run the workflow.
29+
30+
---
31+
*This issue was automatically created by the Rector workflow job.*

‎.github/ISSUE_TEMPLATE/wp-dependencies-failure.md‎

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

‎.github/labeler.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ testing:
6767
- any-glob-to-any-file: phpmd.xml
6868
- any-glob-to-any-file: phpstan.neon
6969
- any-glob-to-any-file: psalm.xml
70+
- any-glob-to-any-file: rector.php
7071
- any-glob-to-any-file: .markdownlint.json
7172
- any-glob-to-any-file: .markdownlint-cli2.jsonc
7273
- any-glob-to-any-file: .mypy.ini

‎.github/scripts/test-automation.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ def accepts_jobs(records: list[dict[str, str]]) -> bool:
246246
== 0
247247
)
248248

249-
self.assertEqual(22, len(jobs))
249+
self.assertEqual(23, len(jobs))
250250
with patch.dict(os.environ, PATH=f"{self.root / 'bin'}:{os.environ['PATH']}"):
251251
self.assertTrue(accepts_jobs(jobs))
252252
for index in range(len(jobs)):

‎.github/workflows/release.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ jobs:
105105
["WP Plugin Check (PHP 8.3)", "PHPCS (PHP 8.3)", "WP VIP CS (PHP 8.3)",
106106
"PHPMD (PHP 8.3)", "Psalm Static Analysis (PHP 8.3)",
107107
"Security Scan (PHP 8.3)", "PHPStan for WP (PHP 8.3)",
108+
"Rector (PHP 8.3)",
108109
"Lint (Node 24)", "Unit Test Coverage (PHP 8.4)",
109110
( ["8.2", "8.3", "8.4", "8.5"][] as $php |
110111
["7.0", "latest", "nightly"][] as $wp |

‎.github/workflows/wp-compatibility-test.yml‎

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# - PHP compatibility testing across multiple PHP versions (8.2, 8.3, 8.4, 8.5)
66
# - WordPress compatibility testing across multiple WP versions (7.0, latest, nightly)
77
# - PHPStan static analysis for WordPress-specific code quality
8+
# - Rector dry run, which fails on PHP that a current idiom would replace
89
# - WordPress security vulnerability scanning using pattern analysis
910
# - PHPCS code standards validation for WordPress coding standards
1011
# - Psalm static analysis and taint analysis
@@ -1067,6 +1068,106 @@ jobs:
10671068
filename: .github/ISSUE_TEMPLATE/phpstan-failure.md
10681069
update_existing: false
10691070

1071+
rector:
1072+
name: Rector (PHP 8.3)
1073+
runs-on: ubuntu-latest
1074+
# The job files an issue when it fails on main.
1075+
permissions:
1076+
contents: read
1077+
issues: write
1078+
timeout-minutes: 30
1079+
steps:
1080+
- name: Checkout code
1081+
id: checkout_code
1082+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
1083+
with:
1084+
persist-credentials: false
1085+
# Always fetch the latest commit, disable any caching
1086+
fetch-depth: 0
1087+
clean: true
1088+
1089+
- name: Setup PHP 8.3
1090+
id: setup_php_8_3
1091+
uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # 2.40.0
1092+
with:
1093+
php-version: '8.3'
1094+
extensions: mysqli, curl, zip, intl, gd, mbstring, fileinfo, xml
1095+
coverage: none
1096+
tools: composer:v2
1097+
1098+
- name: Clear any existing composer cache
1099+
id: clear_any_existing_composer_cache
1100+
run: |
1101+
composer clear-cache || true
1102+
rm -rf vendor/ composer.lock || true
1103+
1104+
- name: Install Composer dependencies (no cache)
1105+
id: install_composer_dependencies_no_cache
1106+
run: |
1107+
composer install --prefer-dist --no-progress --no-cache
1108+
1109+
- name: Run Rector dry run
1110+
id: run_rector_dry_run
1111+
# The dry run changes nothing and fails when any configured rule would change the code.
1112+
run: |
1113+
vendor/bin/rector --version
1114+
vendor/bin/rector process --dry-run --no-progress-bar
1115+
1116+
- name: Preserve diagnostic summary
1117+
id: preserve_diagnostics
1118+
if: ${{ always() }}
1119+
continue-on-error: true
1120+
env:
1121+
STEP_RESULTS: |
1122+
checkout_code=${{ steps.checkout_code.outcome }}
1123+
setup_php_8_3=${{ steps.setup_php_8_3.outcome }}
1124+
clear_any_existing_composer_cache=${{ steps.clear_any_existing_composer_cache.outcome }}
1125+
install_composer_dependencies_no_cache=${{ steps.install_composer_dependencies_no_cache.outcome }}
1126+
run_rector_dry_run=${{ steps.run_rector_dry_run.outcome }}
1127+
run: |
1128+
mkdir -p "$RUNNER_TEMP/es-optimizer-diagnostics"
1129+
printf '%s\n' "$STEP_RESULTS" > "$RUNNER_TEMP/es-optimizer-diagnostics/steps.txt"
1130+
printf 'commit=%s\njob=%s\n' "$GITHUB_SHA" "$GITHUB_JOB" > "$RUNNER_TEMP/es-optimizer-diagnostics/run.txt"
1131+
if command -v php >/dev/null; then
1132+
php -r 'echo PHP_VERSION, PHP_EOL;' > "$RUNNER_TEMP/es-optimizer-diagnostics/php.txt"
1133+
fi
1134+
if command -v composer >/dev/null && [ -f vendor/composer/installed.json ]; then
1135+
php -r '$data = json_decode(file_get_contents("vendor/composer/installed.json"), true, 512, JSON_THROW_ON_ERROR); foreach ($data["packages"] ?? $data as $package) { echo $package["name"], " ", $package["version"], PHP_EOL; }' > "$RUNNER_TEMP/es-optimizer-diagnostics/dependencies.txt"
1136+
fi
1137+
# Never upload config, authentication data, SQL, exports, or arbitrary logs.
1138+
# Refuse oversized or linked diagnostics instead of uploading them.
1139+
find "$RUNNER_TEMP/es-optimizer-diagnostics" -type l -delete
1140+
find "$RUNNER_TEMP/es-optimizer-diagnostics" -type f -size +2M -delete
1141+
1142+
- name: Upload diagnostic summary
1143+
id: upload_diagnostics
1144+
if: ${{ always() }}
1145+
continue-on-error: true
1146+
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
1147+
with:
1148+
name: wp-compat-rector
1149+
path: |
1150+
${{ runner.temp }}/es-optimizer-diagnostics/run.txt
1151+
${{ runner.temp }}/es-optimizer-diagnostics/steps.txt
1152+
${{ runner.temp }}/es-optimizer-diagnostics/php.txt
1153+
${{ runner.temp }}/es-optimizer-diagnostics/dependencies.txt
1154+
retention-days: 7
1155+
if-no-files-found: warn
1156+
1157+
- name: Create issue on Rector failure
1158+
id: create_issue_on_rector_failure
1159+
if: ${{ failure() && (github.event_name == 'push' || github.event_name == 'workflow_dispatch') && github.actor != 'dependabot[bot]' }}
1160+
uses: JasonEtco/create-an-issue@1b14a70e4d8dc185e5cc76d3bec9eab20257b2c5 # v2.9.2
1161+
env:
1162+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1163+
FAILURE_STAGE: ${{ steps.checkout_code.outcome == 'failure' && 'checkout_code' || steps.setup_php_8_3.outcome == 'failure' && 'setup_php_8_3' || steps.clear_any_existing_composer_cache.outcome == 'failure' && 'clear_any_existing_composer_cache' || steps.install_composer_dependencies_no_cache.outcome == 'failure' && 'install_composer_dependencies_no_cache' || steps.run_rector_dry_run.outcome == 'failure' && 'run_rector_dry_run' || 'unknown_or_canceled' }}
1164+
PHP_VERSION: '8.3'
1165+
RUN_ID: ${{ github.run_id }}
1166+
WORKFLOW_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
1167+
with:
1168+
filename: .github/ISSUE_TEMPLATE/rector-failure.md
1169+
update_existing: false
1170+
10701171
lint:
10711172
name: Lint (Node 24)
10721173
runs-on: ubuntu-latest

0 commit comments

Comments
 (0)