Skip to content

Commit 5fcea91

Browse files
Use rector-src#dev-upgrade-to-php-parser5-and-phpstan-2 (#408)
* Use rector-src#dev-upgrade-to-php-parser5-and-phpstan-2 * [ci-review] Rector Rectify * update node class usage * [ci-review] Rector Rectify * fix throw as expr * [ci-review] Rector Rectify * fix phpstan * require dev phpstan webmozart v2 and fix phsptan message return --------- Co-authored-by: GitHub Action <[email protected]>
1 parent b75c030 commit 5fcea91

15 files changed

+80
-60
lines changed

composer.json

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,16 @@
77
"php": ">=8.2"
88
},
99
"require-dev": {
10-
"rector/rector-src": "dev-main",
10+
"rector/rector-src": "dev-upgrade-to-php-parser5-and-phpstan-2",
1111
"phpunit/phpunit": "^10.5",
12-
"phpstan/phpstan": "^1.12",
13-
"symplify/phpstan-rules": "^13.0",
14-
"symplify/phpstan-extensions": "^11.4",
12+
"phpstan/phpstan": "^2.0",
1513
"symplify/easy-coding-standard": "^12.3",
1614
"phpstan/extension-installer": "^1.4",
17-
"phpstan/phpstan-webmozart-assert": "^1.2",
1815
"symplify/vendor-patches": "^11.3",
1916
"tracy/tracy": "^2.10",
2017
"tomasvotruba/class-leak": "^1.2",
21-
"rector/type-perfect": "^1.0",
22-
"rector/swiss-knife": "^1.0"
18+
"rector/swiss-knife": "^1.0",
19+
"phpstan/phpstan-webmozart-assert": "^2.0"
2320
},
2421
"autoload": {
2522
"psr-4": {
@@ -43,7 +40,7 @@
4340
"@docs",
4441
"phpunit"
4542
],
46-
"phpstan": "vendor/bin/phpstan analyse --ansi --error-format symplify",
43+
"phpstan": "vendor/bin/phpstan analyse --ansi",
4744
"check-cs": "vendor/bin/ecs check --ansi",
4845
"class-leak": "vendor/bin/class-leak check config src rules --skip-suffix \"Rector\"",
4946
"fix-cs": "vendor/bin/ecs check --fix --ansi",

phpstan.neon

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@ parameters:
1919
- */Fixture/*
2020
- */Expected/*
2121

22-
# see https://github.com/rectorphp/type-perfect/
23-
type_perfect:
24-
no_mixed: true
25-
null_over_false: true
26-
narrow_param: true
27-
narrow_return: true
22+
# to be enabled later once rector upgraded to use phpstan v2
23+
# # see https://github.com/rectorphp/type-perfect/
24+
# type_perfect:
25+
# no_mixed: true
26+
# null_over_false: true
27+
# narrow_param: true
28+
# narrow_return: true
2829

2930
ignoreErrors:
3031
# phpstan false positive
@@ -34,3 +35,25 @@ parameters:
3435
- '#Access to an undefined property Rector\\Contract\\PhpParser\\Node\\StmtsAwareInterface\:\:\$stmts#'
3536

3637
- '#PhpParser\\Node\\Stmt\\Expression is not generic#'
38+
39+
# more advanced usage, but not always working
40+
# see https://github.com/rectorphp/rector-src/actions/runs/11798721617/job/32865546672?pr=6422#step:5:110
41+
- '#Doing instanceof PHPStan\\Type\\.+ is error\-prone and deprecated#'
42+
43+
-
44+
identifier: instanceof.alwaysTrue
45+
46+
-
47+
identifier: argument.type
48+
49+
# phpstan instanceof
50+
-
51+
identifier: phpstanApi.instanceofAssumption
52+
53+
-
54+
identifier: phpstanApi.varTagAssumption
55+
56+
-
57+
identifier: assign.propertyType
58+
59+
- '#::provideMinPhpVersion\(\) never returns \d+ so it can be removed from the return type#'

rules/CodeQuality/NodeFactory/NestedClosureAssertFactory.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use PhpParser\Node\Expr\MethodCall;
1717
use PhpParser\Node\Expr\Variable;
1818
use PhpParser\Node\Identifier;
19-
use PhpParser\Node\Scalar\LNumber;
19+
use PhpParser\Node\Scalar\Int_;
2020
use PhpParser\Node\Stmt;
2121
use PhpParser\Node\Stmt\Expression;
2222
use Rector\PHPUnit\Enum\ConsecutiveVariable;
@@ -59,7 +59,7 @@ public function create(MethodCall $assertMethodCall, int $assertKey): array
5959

6060
$stmts = [new Expression($callbackAssign)];
6161

62-
$parametersArrayDimFetch = new ArrayDimFetch(new Variable('parameters'), new LNumber($assertKey));
62+
$parametersArrayDimFetch = new ArrayDimFetch(new Variable('parameters'), new Int_($assertKey));
6363
$callbackFuncCall = new FuncCall($callbackVariable, [new Arg($parametersArrayDimFetch)]);
6464

6565
// add assert true to the callback
@@ -77,7 +77,7 @@ private function createAssertSameParameters(Expr $comparedExpr, int $assertKey):
7777
// use assert same directly instead
7878
$args = [
7979
new Arg($comparedExpr),
80-
new Arg(new ArrayDimFetch(new Variable('parameters'), new LNumber($assertKey))),
80+
new Arg(new ArrayDimFetch(new Variable('parameters'), new Int_($assertKey))),
8181
];
8282

8383
$assertSameMethodCall = new MethodCall(new Variable('this'), new Identifier('assertSame'), $args);
@@ -90,7 +90,7 @@ private function createAssertSameParameters(Expr $comparedExpr, int $assertKey):
9090
*/
9191
private function createAssertNotEmpty(int $assertKey, string $emptyMethodName): array
9292
{
93-
$arrayDimFetch = new ArrayDimFetch(new Variable(ConsecutiveVariable::PARAMETERS), new LNumber($assertKey));
93+
$arrayDimFetch = new ArrayDimFetch(new Variable(ConsecutiveVariable::PARAMETERS), new Int_($assertKey));
9494

9595
$assertEmptyMethodCall = new MethodCall(new Variable('this'), new Identifier($emptyMethodName), [
9696
new Arg($arrayDimFetch),

rules/CodeQuality/Rector/ClassMethod/CreateMockToAnonymousClassRector.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Rector\PHPUnit\CodeQuality\Rector\ClassMethod;
66

7+
use PhpParser\Modifiers;
78
use PhpParser\Node;
89
use PhpParser\Node\Arg;
910
use PhpParser\Node\Expr;
@@ -246,7 +247,7 @@ private function createMockedClassMethod(MethodCall $rootMethodCall, MethodCall
246247
->value;
247248

248249
return new ClassMethod($methodName, [
249-
'flags' => Class_::MODIFIER_PUBLIC,
250+
'flags' => Modifiers::PUBLIC,
250251
'stmts' => [new Return_($returnedExpr)],
251252
]);
252253
}

rules/CodeQuality/Rector/ClassMethod/DataProviderArrayItemsNewLinedRector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
namespace Rector\PHPUnit\CodeQuality\Rector\ClassMethod;
66

77
use PhpParser\Node;
8+
use PhpParser\Node\ArrayItem;
89
use PhpParser\Node\Expr\Array_;
9-
use PhpParser\Node\Expr\ArrayItem;
1010
use PhpParser\Node\Stmt\ClassMethod;
1111
use PhpParser\Node\Stmt\Return_;
1212
use Rector\NodeTypeResolver\Node\AttributeKey;

rules/CodeQuality/Rector/Class_/SetUpBeforeClassToSetUpRector.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Rector\PHPUnit\CodeQuality\Rector\Class_;
66

7+
use PhpParser\Modifiers;
78
use PhpParser\Node;
89
use PhpParser\Node\Expr\Assign;
910
use PhpParser\Node\Expr\PropertyFetch;
@@ -134,13 +135,13 @@ public function refactor(Node $node): ?Node
134135
}
135136

136137
// remove static flag
137-
$setUpBeforeClassMethod->flags -= Class_::MODIFIER_STATIC;
138+
$setUpBeforeClassMethod->flags -= Modifiers::STATIC;
138139

139140
// remove public flag
140-
$setUpBeforeClassMethod->flags -= Class_::MODIFIER_PUBLIC;
141+
$setUpBeforeClassMethod->flags -= Modifiers::PUBLIC;
141142

142143
// make protected
143-
$setUpBeforeClassMethod->flags += Class_::MODIFIER_PROTECTED;
144+
$setUpBeforeClassMethod->flags += Modifiers::PROTECTED;
144145

145146
$setUpBeforeClassMethod->name = new Identifier('setUp');
146147

@@ -150,7 +151,7 @@ public function refactor(Node $node): ?Node
150151
}
151152

152153
if ($this->isNames($property, $changedPropertyNames)) {
153-
$property->flags -= Class_::MODIFIER_STATIC;
154+
$property->flags -= Modifiers::STATIC;
154155
}
155156
}
156157

rules/CodeQuality/Rector/Class_/TestWithToDataProviderRector.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66

77
use Nette\Utils\Json;
88
use Nette\Utils\Strings;
9+
use PhpParser\Modifiers;
910
use PhpParser\Node;
11+
use PhpParser\Node\ArrayItem;
1012
use PhpParser\Node\Expr;
1113
use PhpParser\Node\Expr\Array_;
12-
use PhpParser\Node\Expr\ArrayItem;
1314
use PhpParser\Node\Expr\ConstFetch;
1415
use PhpParser\Node\Name;
1516
use PhpParser\Node\Scalar\String_;
@@ -174,7 +175,7 @@ private function refactorClassMethod(Class_ $class, ClassMethod $classMethod): v
174175
}
175176

176177
$providerMethod = new ClassMethod($dataProviderName);
177-
$providerMethod->flags = Class_::MODIFIER_PUBLIC;
178+
$providerMethod->flags = Modifiers::PUBLIC;
178179
$providerMethod->stmts[] = new Return_($returnValue);
179180
$this->classInsertManipulator->addAsFirstMethod($class, $providerMethod);
180181
}

rules/CodeQuality/Rector/MethodCall/AssertEqualsOrAssertSameFloatParameterToSpecificMethodsTypeRector.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use PhpParser\Node\Expr\ConstFetch;
1010
use PhpParser\Node\Expr\MethodCall;
1111
use PhpParser\Node\Name;
12-
use PhpParser\Node\Scalar\DNumber;
12+
use PhpParser\Node\Scalar\Float_;
1313
use Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer;
1414
use Rector\PHPUnit\NodeFactory\AssertCallFactory;
1515
use Rector\Rector\AbstractRector;
@@ -74,7 +74,7 @@ public function refactor(Node $node): ?Node
7474
$args = $node->getArgs();
7575

7676
$firstValue = $args[0]->value;
77-
if (! $firstValue instanceof DNumber) {
77+
if (! $firstValue instanceof Float_) {
7878
return null;
7979
}
8080

rules/CodeQuality/Rector/MethodCall/AssertEqualsToSameRector.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use PhpParser\Node\Expr\ClassConstFetch;
1010
use PhpParser\Node\Expr\MethodCall;
1111
use PhpParser\Node\Expr\StaticCall;
12-
use PhpParser\Node\Scalar\Encapsed;
12+
use PhpParser\Node\Scalar\InterpolatedString;
1313
use PHPStan\Type\Constant\ConstantArrayType;
1414
use PHPStan\Type\FloatType;
1515
use PHPStan\Type\IntegerType;
@@ -152,7 +152,7 @@ private function isScalarOrEnumValue(Expr $expr): bool
152152
return true;
153153
}
154154

155-
if ($expr instanceof Encapsed) {
155+
if ($expr instanceof InterpolatedString) {
156156
return true;
157157
}
158158

rules/CodeQuality/Rector/MethodCall/AssertRegExpRector.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use PhpParser\Node\Expr\StaticCall;
1313
use PhpParser\Node\Expr\Variable;
1414
use PhpParser\Node\Identifier;
15-
use PhpParser\Node\Scalar\LNumber;
15+
use PhpParser\Node\Scalar\Int_;
1616
use PhpParser\Node\Stmt\Expression;
1717
use Rector\Contract\PhpParser\Node\StmtsAwareInterface;
1818
use Rector\Exception\ShouldNotHappenException;
@@ -159,7 +159,7 @@ public function refactor(Node $node): ?Node
159159

160160
private function resolveOldCondition(Expr $expr): int
161161
{
162-
if ($expr instanceof LNumber) {
162+
if ($expr instanceof Int_) {
163163
return $expr->value;
164164
}
165165

0 commit comments

Comments
 (0)