From 92504be5167ebf858c562ceb37b7849873ecac3e Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Mon, 27 Oct 2025 23:42:09 +0100 Subject: [PATCH 1/5] require php parser 5.4 --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index 1aa3e32..6d76366 100644 --- a/composer.json +++ b/composer.json @@ -4,6 +4,7 @@ "require-dev": { "php": "^8.2", "phpunit/phpunit": "10.*|11.*|12.*", + "nikic/php-parser": "5.4.*", "rector/rector": "dev-main", "phpstan/phpstan": "^2.1" }, From 7d2e0a8e74774d5850c4d02a422d8d87028cafda Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Mon, 27 Oct 2025 23:52:31 +0100 Subject: [PATCH 2/5] kick off laravel rector, php-parser 5.4 and phpunit 11 test using getArg() calls on CallLike --- .../rector_laravel_php_parser.yaml.yml | 27 +++++++++++++++ composer.json | 6 ++-- fixture/FixtureWithFuncCall.php | 11 +++++++ rector.php | 19 +++++++++++ src/Rector/UseGetArgRector.php | 33 +++++++++++++++++++ 5 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/rector_laravel_php_parser.yaml.yml create mode 100644 fixture/FixtureWithFuncCall.php create mode 100644 rector.php create mode 100644 src/Rector/UseGetArgRector.php diff --git a/.github/workflows/rector_laravel_php_parser.yaml.yml b/.github/workflows/rector_laravel_php_parser.yaml.yml new file mode 100644 index 0000000..5d4b792 --- /dev/null +++ b/.github/workflows/rector_laravel_php_parser.yaml.yml @@ -0,0 +1,27 @@ +# see https://github.com/rectorphp/rector/issues/9470#issuecomment-3453388719 +name: Rector Laravel and PHP Parser + +on: + pull_request: null + push: + branches: + - main + +jobs: + compat_tests: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - + uses: shivammathur/setup-php@v2 + with: + php-version: "8.1" + coverage: none + + - uses: "ramsey/composer-install@v2" + + - run: composer require "phpunit/phpunit:11.*" -W + + - run: vendor/bin/rector p fixture --debug --clear-cache diff --git a/composer.json b/composer.json index 6d76366..0335271 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,8 @@ "phpunit/phpunit": "10.*|11.*|12.*", "nikic/php-parser": "5.4.*", "rector/rector": "dev-main", - "phpstan/phpstan": "^2.1" + "phpstan/phpstan": "2.1.*", + "driftingly/rector-laravel": "^0.27.0" }, "autoload": { "psr-4": { @@ -15,7 +16,8 @@ }, "autoload-dev": { "psr-4": { - "Rector\\RectorCompatTests\\Tests\\": "tests" + "Rector\\RectorCompatTests\\Tests\\": "tests", + "Fixture\\": "fixture" } } } diff --git a/fixture/FixtureWithFuncCall.php b/fixture/FixtureWithFuncCall.php new file mode 100644 index 0000000..902dca4 --- /dev/null +++ b/fixture/FixtureWithFuncCall.php @@ -0,0 +1,11 @@ +withPaths([ + __DIR__ . '/src', + __DIR__ . '/tests', + __DIR__ . '/fixture', + ]) + // uncomment to reach your current PHP version + // ->withPhpSets() + ->withRules([UseGetArgRector::class]) + ->withTypeCoverageLevel(0) + ->withDeadCodeLevel(0) + ->withCodeQualityLevel(0); diff --git a/src/Rector/UseGetArgRector.php b/src/Rector/UseGetArgRector.php new file mode 100644 index 0000000..2d8751a --- /dev/null +++ b/src/Rector/UseGetArgRector.php @@ -0,0 +1,33 @@ +> + */ + public function getNodeTypes(): array + { + return [FuncCall::class]; + } + + /** + * @param FuncCall $node + */ + public function refactor(Node $node) + { + // here we should load Rector's php-parser 5.6, that already has getArg() method + + return $node->getArg('name', 5); + } +} From 10009e5738ccbd351b8986baa9c058d0f3323897 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Mon, 27 Oct 2025 23:55:05 +0100 Subject: [PATCH 3/5] use newer laravel rector version --- composer.json | 4 ++-- rector.php | 5 ++--- src/Rector/UseGetArgRector.php | 10 +++++++++- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/composer.json b/composer.json index 0335271..c190119 100644 --- a/composer.json +++ b/composer.json @@ -5,9 +5,9 @@ "php": "^8.2", "phpunit/phpunit": "10.*|11.*|12.*", "nikic/php-parser": "5.4.*", - "rector/rector": "dev-main", + "rector/rector": "dev-main as 2.2.6", "phpstan/phpstan": "2.1.*", - "driftingly/rector-laravel": "^0.27.0" + "driftingly/rector-laravel": "^2.1" }, "autoload": { "psr-4": { diff --git a/rector.php b/rector.php index 5801cee..f19fe5d 100644 --- a/rector.php +++ b/rector.php @@ -4,6 +4,7 @@ use Rector\Config\RectorConfig; use Rector\RectorCompatTests\Rector\UseGetArgRector; +use RectorLaravel\Set\LaravelSetList; return RectorConfig::configure() ->withPaths([ @@ -11,9 +12,7 @@ __DIR__ . '/tests', __DIR__ . '/fixture', ]) - // uncomment to reach your current PHP version - // ->withPhpSets() - ->withRules([UseGetArgRector::class]) + ->withRules([UseGetArgRector::class]) ->withTypeCoverageLevel(0) ->withDeadCodeLevel(0) ->withCodeQualityLevel(0); diff --git a/src/Rector/UseGetArgRector.php b/src/Rector/UseGetArgRector.php index 2d8751a..305bd2f 100644 --- a/src/Rector/UseGetArgRector.php +++ b/src/Rector/UseGetArgRector.php @@ -6,7 +6,9 @@ use PhpParser\Modifiers; use PhpParser\Node; +use PhpParser\Node\Arg; use PhpParser\Node\Expr\FuncCall; +use PhpParser\Node\Scalar\String_; use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\Function_; use Rector\Rector\AbstractRector; @@ -27,7 +29,13 @@ public function getNodeTypes(): array public function refactor(Node $node) { // here we should load Rector's php-parser 5.6, that already has getArg() method + $firstArg = $node->getArg('', 0); + if (! $firstArg instanceof Arg) { + return null;; + } - return $node->getArg('name', 5); + $firstArg->value = new String_('changed_value'); + + return $node; } } From 067a94a448c3f56f67b83a3c2eeb836597357116 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Tue, 28 Oct 2025 00:08:55 +0100 Subject: [PATCH 4/5] fixup! use newer laravel rector version --- .github/workflows/compat_tests_global_rector.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/compat_tests_global_rector.yaml b/.github/workflows/compat_tests_global_rector.yaml index 0d119bd..a828e55 100644 --- a/.github/workflows/compat_tests_global_rector.yaml +++ b/.github/workflows/compat_tests_global_rector.yaml @@ -14,7 +14,7 @@ jobs: actions: - name: 'Rector dev + PHPUnit 12 global for Rector' - run: composer require --dev "rector/rector:dev-main" -W + run: composer require --dev "rector/rector:dev-main as 2.2.6" -W php: 8.3 name: ${{ matrix.actions.name }} From a63d2d0468de315b5c40f92afda426f582fbe682 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Tue, 28 Oct 2025 00:12:10 +0100 Subject: [PATCH 5/5] fixup! fixup! use newer laravel rector version --- .github/workflows/rector_laravel_php_parser.yaml.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/rector_laravel_php_parser.yaml.yml b/.github/workflows/rector_laravel_php_parser.yaml.yml index 5d4b792..0d2667a 100644 --- a/.github/workflows/rector_laravel_php_parser.yaml.yml +++ b/.github/workflows/rector_laravel_php_parser.yaml.yml @@ -17,7 +17,7 @@ jobs: - uses: shivammathur/setup-php@v2 with: - php-version: "8.1" + php-version: "8.2" coverage: none - uses: "ramsey/composer-install@v2"