Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/compat_tests_global_rector.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
27 changes: 27 additions & 0 deletions .github/workflows/rector_laravel_php_parser.yaml.yml
Original file line number Diff line number Diff line change
@@ -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
9 changes: 6 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -14,7 +16,8 @@
},
"autoload-dev": {
"psr-4": {
"Rector\\RectorCompatTests\\Tests\\": "tests"
"Rector\\RectorCompatTests\\Tests\\": "tests",
"Fixture\\": "fixture"
}
}
}
11 changes: 11 additions & 0 deletions fixture/FixtureWithFuncCall.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Fixture;

final class FixtureWithFuncCall
{
public function run(): int
{
return strlen('hello');
}
}
18 changes: 18 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\RectorCompatTests\Rector\UseGetArgRector;
use RectorLaravel\Set\LaravelSetList;

return RectorConfig::configure()
->withPaths([
__DIR__ . '/src',
__DIR__ . '/tests',
__DIR__ . '/fixture',
])
->withRules([UseGetArgRector::class])
->withTypeCoverageLevel(0)
->withDeadCodeLevel(0)
->withCodeQualityLevel(0);
41 changes: 41 additions & 0 deletions src/Rector/UseGetArgRector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

namespace Rector\RectorCompatTests\Rector;

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;

final class UseGetArgRector extends AbstractRector
{
/**
* @return array<class-string<Class_>>
*/
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;
}
}