From 391cac11a79ded61ce1f65a162bfffe9ffd1192d Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 6 Apr 2026 17:58:00 +0700 Subject: [PATCH 1/4] [Downgradephp85] Add DowngradeVoidCastRector --- .github/workflows/code_analysis.yaml | 8 +- config/set/downgrade-php85.php | 2 + .../DowngradeVoidCastRectorTest.php | 30 +++++++ .../Fixture/fixture.php.inc | 41 +++++++++ .../Fixture/skip_different_func_call.php.inc | 15 ++++ .../config/configured_rule.php | 10 +++ .../Expression/DowngradeVoidCastRector.php | 84 +++++++++++++++++++ 7 files changed, 188 insertions(+), 2 deletions(-) create mode 100644 rules-tests/DowngradePhp85/Rector/Expression/DowngradeArrayFirstLastRector/DowngradeVoidCastRectorTest.php create mode 100644 rules-tests/DowngradePhp85/Rector/Expression/DowngradeArrayFirstLastRector/Fixture/fixture.php.inc create mode 100644 rules-tests/DowngradePhp85/Rector/Expression/DowngradeArrayFirstLastRector/Fixture/skip_different_func_call.php.inc create mode 100644 rules-tests/DowngradePhp85/Rector/Expression/DowngradeArrayFirstLastRector/config/configured_rule.php create mode 100644 rules/DowngradePhp85/Rector/Expression/DowngradeVoidCastRector.php diff --git a/.github/workflows/code_analysis.yaml b/.github/workflows/code_analysis.yaml index dceab9f1..c22ad256 100644 --- a/.github/workflows/code_analysis.yaml +++ b/.github/workflows/code_analysis.yaml @@ -15,6 +15,10 @@ jobs: strategy: fail-fast: false matrix: + php-version: + - '8.3' + # needed to test (void) cast downgrade syntax + - '8.5' actions: - name: "Validate docs" @@ -40,7 +44,7 @@ jobs: name: 'Tests' run: vendor/bin/phpunit - name: ${{ matrix.actions.name }} + name: ${{ matrix.actions.name }} - PHP ${{ matrix.php-version }} runs-on: ubuntu-latest timeout-minutes: 3 @@ -50,7 +54,7 @@ jobs: - uses: shivammathur/setup-php@v2 with: - php-version: 8.3 + php-version: ${{ matrix.php-version }} coverage: none - uses: "ramsey/composer-install@v2" diff --git a/config/set/downgrade-php85.php b/config/set/downgrade-php85.php index bac19e15..b2b2b876 100644 --- a/config/set/downgrade-php85.php +++ b/config/set/downgrade-php85.php @@ -4,6 +4,7 @@ use Rector\Config\RectorConfig; use Rector\DowngradePhp85\Rector\Class_\DowngradeFinalPropertyPromotionRector; +use Rector\DowngradePhp85\Rector\Expression\DowngradeVoidCastRector; use Rector\DowngradePhp85\Rector\FuncCall\DowngradeArrayFirstLastRector; use Rector\DowngradePhp85\Rector\StmtsAwareInterface\DowngradePipeOperatorRector; use Rector\Renaming\Rector\ClassConstFetch\RenameClassConstFetchRector; @@ -18,6 +19,7 @@ DowngradeArrayFirstLastRector::class, DowngradeFinalPropertyPromotionRector::class, DowngradePipeOperatorRector::class, + DowngradeVoidCastRector::class, ]); // https://wiki.php.net/rfc/deprecations_php_8_5#deprecate_driver_specific_pdo_constants_and_methods diff --git a/rules-tests/DowngradePhp85/Rector/Expression/DowngradeArrayFirstLastRector/DowngradeVoidCastRectorTest.php b/rules-tests/DowngradePhp85/Rector/Expression/DowngradeArrayFirstLastRector/DowngradeVoidCastRectorTest.php new file mode 100644 index 00000000..51fd6f39 --- /dev/null +++ b/rules-tests/DowngradePhp85/Rector/Expression/DowngradeArrayFirstLastRector/DowngradeVoidCastRectorTest.php @@ -0,0 +1,30 @@ +doTestFile($filePath); + } + + public static function provideData(): Iterator + { + return self::yieldFilesFromDirectory(__DIR__ . '/Fixture'); + } + + public function provideConfigFilePath(): string + { + return __DIR__ . '/config/configured_rule.php'; + } +} diff --git a/rules-tests/DowngradePhp85/Rector/Expression/DowngradeArrayFirstLastRector/Fixture/fixture.php.inc b/rules-tests/DowngradePhp85/Rector/Expression/DowngradeArrayFirstLastRector/Fixture/fixture.php.inc new file mode 100644 index 00000000..8bbe5cd8 --- /dev/null +++ b/rules-tests/DowngradePhp85/Rector/Expression/DowngradeArrayFirstLastRector/Fixture/fixture.php.inc @@ -0,0 +1,41 @@ +foo(); + } +} + +?> +----- +foo(); + } +} + +?> diff --git a/rules-tests/DowngradePhp85/Rector/Expression/DowngradeArrayFirstLastRector/Fixture/skip_different_func_call.php.inc b/rules-tests/DowngradePhp85/Rector/Expression/DowngradeArrayFirstLastRector/Fixture/skip_different_func_call.php.inc new file mode 100644 index 00000000..36aa6ce8 --- /dev/null +++ b/rules-tests/DowngradePhp85/Rector/Expression/DowngradeArrayFirstLastRector/Fixture/skip_different_func_call.php.inc @@ -0,0 +1,15 @@ + diff --git a/rules-tests/DowngradePhp85/Rector/Expression/DowngradeArrayFirstLastRector/config/configured_rule.php b/rules-tests/DowngradePhp85/Rector/Expression/DowngradeArrayFirstLastRector/config/configured_rule.php new file mode 100644 index 00000000..1566854b --- /dev/null +++ b/rules-tests/DowngradePhp85/Rector/Expression/DowngradeArrayFirstLastRector/config/configured_rule.php @@ -0,0 +1,10 @@ +rule(DowngradeVoidCastRector::class); +}; diff --git a/rules/DowngradePhp85/Rector/Expression/DowngradeVoidCastRector.php b/rules/DowngradePhp85/Rector/Expression/DowngradeVoidCastRector.php new file mode 100644 index 00000000..931b9f32 --- /dev/null +++ b/rules/DowngradePhp85/Rector/Expression/DowngradeVoidCastRector.php @@ -0,0 +1,84 @@ +expr instanceof Void_) { + return null; + } + + $scope = ScopeFetcher::fetch($node); + $variable = new Variable($this->variableNaming->createCountedValueName('_void', $scope)); + + // the assign is needed to avoid warning + // see https://3v4l.org/ie68D#v8.5.3 vs https://3v4l.org/nLc5J#v8.5.3 + $node->expr = new Assign( + $variable, + $node->expr->expr + ); + return $node; + } +} From 803611697a0cf1499c1bcc8081ed2ef6eb8ce027 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 6 Apr 2026 18:00:04 +0700 Subject: [PATCH 2/4] folder rename --- .../DowngradeVoidCastRectorTest.php | 0 .../Fixture/fixture.php.inc | 0 .../Fixture/skip_different_func_call.php.inc | 0 .../config/configured_rule.php | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename rules-tests/DowngradePhp85/Rector/Expression/{DowngradeArrayFirstLastRector => DowngradeVoidCastRector}/DowngradeVoidCastRectorTest.php (100%) rename rules-tests/DowngradePhp85/Rector/Expression/{DowngradeArrayFirstLastRector => DowngradeVoidCastRector}/Fixture/fixture.php.inc (100%) rename rules-tests/DowngradePhp85/Rector/Expression/{DowngradeArrayFirstLastRector => DowngradeVoidCastRector}/Fixture/skip_different_func_call.php.inc (100%) rename rules-tests/DowngradePhp85/Rector/Expression/{DowngradeArrayFirstLastRector => DowngradeVoidCastRector}/config/configured_rule.php (100%) diff --git a/rules-tests/DowngradePhp85/Rector/Expression/DowngradeArrayFirstLastRector/DowngradeVoidCastRectorTest.php b/rules-tests/DowngradePhp85/Rector/Expression/DowngradeVoidCastRector/DowngradeVoidCastRectorTest.php similarity index 100% rename from rules-tests/DowngradePhp85/Rector/Expression/DowngradeArrayFirstLastRector/DowngradeVoidCastRectorTest.php rename to rules-tests/DowngradePhp85/Rector/Expression/DowngradeVoidCastRector/DowngradeVoidCastRectorTest.php diff --git a/rules-tests/DowngradePhp85/Rector/Expression/DowngradeArrayFirstLastRector/Fixture/fixture.php.inc b/rules-tests/DowngradePhp85/Rector/Expression/DowngradeVoidCastRector/Fixture/fixture.php.inc similarity index 100% rename from rules-tests/DowngradePhp85/Rector/Expression/DowngradeArrayFirstLastRector/Fixture/fixture.php.inc rename to rules-tests/DowngradePhp85/Rector/Expression/DowngradeVoidCastRector/Fixture/fixture.php.inc diff --git a/rules-tests/DowngradePhp85/Rector/Expression/DowngradeArrayFirstLastRector/Fixture/skip_different_func_call.php.inc b/rules-tests/DowngradePhp85/Rector/Expression/DowngradeVoidCastRector/Fixture/skip_different_func_call.php.inc similarity index 100% rename from rules-tests/DowngradePhp85/Rector/Expression/DowngradeArrayFirstLastRector/Fixture/skip_different_func_call.php.inc rename to rules-tests/DowngradePhp85/Rector/Expression/DowngradeVoidCastRector/Fixture/skip_different_func_call.php.inc diff --git a/rules-tests/DowngradePhp85/Rector/Expression/DowngradeArrayFirstLastRector/config/configured_rule.php b/rules-tests/DowngradePhp85/Rector/Expression/DowngradeVoidCastRector/config/configured_rule.php similarity index 100% rename from rules-tests/DowngradePhp85/Rector/Expression/DowngradeArrayFirstLastRector/config/configured_rule.php rename to rules-tests/DowngradePhp85/Rector/Expression/DowngradeVoidCastRector/config/configured_rule.php From bb3bfd72bd225e5dc8f7c6ce1e94f98c0922cab8 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 6 Apr 2026 18:02:01 +0700 Subject: [PATCH 3/4] fix phpstan --- .../ClassMethod/DowngradeTrailingCommasInParamUseRector.php | 4 ++++ .../Rector/Class_/DowngradePropertyPromotionRector.php | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/rules/DowngradePhp80/Rector/ClassMethod/DowngradeTrailingCommasInParamUseRector.php b/rules/DowngradePhp80/Rector/ClassMethod/DowngradeTrailingCommasInParamUseRector.php index dac20d57..1f8f75e2 100644 --- a/rules/DowngradePhp80/Rector/ClassMethod/DowngradeTrailingCommasInParamUseRector.php +++ b/rules/DowngradePhp80/Rector/ClassMethod/DowngradeTrailingCommasInParamUseRector.php @@ -118,6 +118,10 @@ private function cleanTrailingComma(Closure|ClassMethod|Function_ $node, array $ { $lastPosition = array_key_last($array); + if ($lastPosition === null) { + return null; + } + $last = $array[$lastPosition]; if (! $this->followedByCommaAnalyzer->isFollowed($this->file, $last)) { return null; diff --git a/rules/DowngradePhp80/Rector/Class_/DowngradePropertyPromotionRector.php b/rules/DowngradePhp80/Rector/Class_/DowngradePropertyPromotionRector.php index 2879d3a3..dd96ee9a 100644 --- a/rules/DowngradePhp80/Rector/Class_/DowngradePropertyPromotionRector.php +++ b/rules/DowngradePhp80/Rector/Class_/DowngradePropertyPromotionRector.php @@ -112,7 +112,7 @@ private function getOldComments(ClassMethod $constructorClassMethod): array { $oldComments = []; foreach ($constructorClassMethod->params as $param) { - $oldComments[$this->getName($param->var)] = $param->getAttribute(AttributeKey::COMMENTS); + $oldComments[(string) $this->getName($param->var)] = $param->getAttribute(AttributeKey::COMMENTS); } return $oldComments; From d65caf020d9df4d81d5da83672f3e2ef8b7ebc35 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 6 Apr 2026 18:05:07 +0700 Subject: [PATCH 4/4] use php 8.5 to allow test (void) cast syntax --- .github/workflows/code_analysis.yaml | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/.github/workflows/code_analysis.yaml b/.github/workflows/code_analysis.yaml index c22ad256..07712b30 100644 --- a/.github/workflows/code_analysis.yaml +++ b/.github/workflows/code_analysis.yaml @@ -15,10 +15,6 @@ jobs: strategy: fail-fast: false matrix: - php-version: - - '8.3' - # needed to test (void) cast downgrade syntax - - '8.5' actions: - name: "Validate docs" @@ -44,7 +40,7 @@ jobs: name: 'Tests' run: vendor/bin/phpunit - name: ${{ matrix.actions.name }} - PHP ${{ matrix.php-version }} + name: ${{ matrix.actions.name }} runs-on: ubuntu-latest timeout-minutes: 3 @@ -54,7 +50,8 @@ jobs: - uses: shivammathur/setup-php@v2 with: - php-version: ${{ matrix.php-version }} + # use php 8.5 to allow test (void) cast syntax + php-version: 8.5 coverage: none - uses: "ramsey/composer-install@v2"