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 }} 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..0d2667a --- /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.2" + 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 1aa3e32..c190119 100644 --- a/composer.json +++ b/composer.json @@ -4,8 +4,10 @@ "require-dev": { "php": "^8.2", "phpunit/phpunit": "10.*|11.*|12.*", - "rector/rector": "dev-main", - "phpstan/phpstan": "^2.1" + "nikic/php-parser": "5.4.*", + "rector/rector": "dev-main as 2.2.6", + "phpstan/phpstan": "2.1.*", + "driftingly/rector-laravel": "^2.1" }, "autoload": { "psr-4": { @@ -14,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', + ]) + ->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..305bd2f --- /dev/null +++ b/src/Rector/UseGetArgRector.php @@ -0,0 +1,41 @@ +> + */ + 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 + $firstArg = $node->getArg('', 0); + if (! $firstArg instanceof Arg) { + return null;; + } + + $firstArg->value = new String_('changed_value'); + + return $node; + } +}