Skip to content

Commit 7d2e0a8

Browse files
committed
kick off laravel rector, php-parser 5.4 and phpunit 11 test using getArg() calls on CallLike
1 parent 92504be commit 7d2e0a8

File tree

5 files changed

+94
-2
lines changed

5 files changed

+94
-2
lines changed
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.1"
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: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"phpunit/phpunit": "10.*|11.*|12.*",
77
"nikic/php-parser": "5.4.*",
88
"rector/rector": "dev-main",
9-
"phpstan/phpstan": "^2.1"
9+
"phpstan/phpstan": "2.1.*",
10+
"driftingly/rector-laravel": "^0.27.0"
1011
},
1112
"autoload": {
1213
"psr-4": {
@@ -15,7 +16,8 @@
1516
},
1617
"autoload-dev": {
1718
"psr-4": {
18-
"Rector\\RectorCompatTests\\Tests\\": "tests"
19+
"Rector\\RectorCompatTests\\Tests\\": "tests",
20+
"Fixture\\": "fixture"
1921
}
2022
}
2123
}

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: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\Config\RectorConfig;
6+
use Rector\RectorCompatTests\Rector\UseGetArgRector;
7+
8+
return RectorConfig::configure()
9+
->withPaths([
10+
__DIR__ . '/src',
11+
__DIR__ . '/tests',
12+
__DIR__ . '/fixture',
13+
])
14+
// uncomment to reach your current PHP version
15+
// ->withPhpSets()
16+
->withRules([UseGetArgRector::class])
17+
->withTypeCoverageLevel(0)
18+
->withDeadCodeLevel(0)
19+
->withCodeQualityLevel(0);

src/Rector/UseGetArgRector.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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\Expr\FuncCall;
10+
use PhpParser\Node\Stmt\Class_;
11+
use PhpParser\Node\Stmt\Function_;
12+
use Rector\Rector\AbstractRector;
13+
14+
final class UseGetArgRector extends AbstractRector
15+
{
16+
/**
17+
* @return array<class-string<Class_>>
18+
*/
19+
public function getNodeTypes(): array
20+
{
21+
return [FuncCall::class];
22+
}
23+
24+
/**
25+
* @param FuncCall $node
26+
*/
27+
public function refactor(Node $node)
28+
{
29+
// here we should load Rector's php-parser 5.6, that already has getArg() method
30+
31+
return $node->getArg('name', 5);
32+
}
33+
}

0 commit comments

Comments
 (0)