Skip to content

Commit d62178f

Browse files
authored
[test] laravel rector 2.1, php-parser 5.4 and phpunit 11 test using getArg() calls on CallLike (#11)
* require php parser 5.4 * kick off laravel rector, php-parser 5.4 and phpunit 11 test using getArg() calls on CallLike * use newer laravel rector version * fixup! use newer laravel rector version * fixup! fixup! use newer laravel rector version
1 parent 32cdf6e commit d62178f

File tree

6 files changed

+104
-4
lines changed

6 files changed

+104
-4
lines changed

.github/workflows/compat_tests_global_rector.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
actions:
1515
-
1616
name: 'Rector dev + PHPUnit 12 global for Rector'
17-
run: composer require --dev "rector/rector:dev-main" -W
17+
run: composer require --dev "rector/rector:dev-main as 2.2.6" -W
1818
php: 8.3
1919

2020
name: ${{ matrix.actions.name }}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# see https://github.com/rectorphp/rector/issues/9470#issuecomment-3453388719
2+
name: Rector Laravel and PHP Parser
3+
4+
on:
5+
pull_request: null
6+
push:
7+
branches:
8+
- main
9+
10+
jobs:
11+
compat_tests:
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- uses: actions/checkout@v4
16+
17+
-
18+
uses: shivammathur/setup-php@v2
19+
with:
20+
php-version: "8.2"
21+
coverage: none
22+
23+
- uses: "ramsey/composer-install@v2"
24+
25+
- run: composer require "phpunit/phpunit:11.*" -W
26+
27+
- run: vendor/bin/rector p fixture --debug --clear-cache

composer.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
"require-dev": {
55
"php": "^8.2",
66
"phpunit/phpunit": "10.*|11.*|12.*",
7-
"rector/rector": "dev-main",
8-
"phpstan/phpstan": "^2.1"
7+
"nikic/php-parser": "5.4.*",
8+
"rector/rector": "dev-main as 2.2.6",
9+
"phpstan/phpstan": "2.1.*",
10+
"driftingly/rector-laravel": "^2.1"
911
},
1012
"autoload": {
1113
"psr-4": {
@@ -14,7 +16,8 @@
1416
},
1517
"autoload-dev": {
1618
"psr-4": {
17-
"Rector\\RectorCompatTests\\Tests\\": "tests"
19+
"Rector\\RectorCompatTests\\Tests\\": "tests",
20+
"Fixture\\": "fixture"
1821
}
1922
}
2023
}

fixture/FixtureWithFuncCall.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace Fixture;
4+
5+
final class FixtureWithFuncCall
6+
{
7+
public function run(): int
8+
{
9+
return strlen('hello');
10+
}
11+
}

rector.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\Config\RectorConfig;
6+
use Rector\RectorCompatTests\Rector\UseGetArgRector;
7+
use RectorLaravel\Set\LaravelSetList;
8+
9+
return RectorConfig::configure()
10+
->withPaths([
11+
__DIR__ . '/src',
12+
__DIR__ . '/tests',
13+
__DIR__ . '/fixture',
14+
])
15+
->withRules([UseGetArgRector::class])
16+
->withTypeCoverageLevel(0)
17+
->withDeadCodeLevel(0)
18+
->withCodeQualityLevel(0);

src/Rector/UseGetArgRector.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rector\RectorCompatTests\Rector;
6+
7+
use PhpParser\Modifiers;
8+
use PhpParser\Node;
9+
use PhpParser\Node\Arg;
10+
use PhpParser\Node\Expr\FuncCall;
11+
use PhpParser\Node\Scalar\String_;
12+
use PhpParser\Node\Stmt\Class_;
13+
use PhpParser\Node\Stmt\Function_;
14+
use Rector\Rector\AbstractRector;
15+
16+
final class UseGetArgRector extends AbstractRector
17+
{
18+
/**
19+
* @return array<class-string<Class_>>
20+
*/
21+
public function getNodeTypes(): array
22+
{
23+
return [FuncCall::class];
24+
}
25+
26+
/**
27+
* @param FuncCall $node
28+
*/
29+
public function refactor(Node $node)
30+
{
31+
// here we should load Rector's php-parser 5.6, that already has getArg() method
32+
$firstArg = $node->getArg('', 0);
33+
if (! $firstArg instanceof Arg) {
34+
return null;;
35+
}
36+
37+
$firstArg->value = new String_('changed_value');
38+
39+
return $node;
40+
}
41+
}

0 commit comments

Comments
 (0)