Skip to content

Commit df4a94b

Browse files
authored
Upgrade to PHPStan 2.0 (#63)
1 parent 3211cbc commit df4a94b

18 files changed

+73
-39
lines changed

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
],
1313
"require": {
1414
"php": "~8.3.0 || ~8.4.0",
15-
"phpstan/phpstan": "^1.12.9"
15+
"phpstan/phpstan": "^2"
1616
},
1717
"require-dev": {
1818
"nette/di": "^3.2.3",
1919
"nette/neon": "^3.4.4",
20-
"nikic/php-parser": "^4.19.2 || ^5.2.0",
21-
"phpstan/phpstan-phpunit": "^1.4.0",
20+
"nikic/php-parser": "^4.19.2 || ^5.3.1",
21+
"phpstan/phpstan-phpunit": "^2",
2222
"phpunit/phpunit": "^11.4.3",
2323
"slam/php-cs-fixer-extensions": "^3.12.0"
2424
},

lib/AccessGlobalVariableWithinContextRule.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use PhpParser\Node;
88
use PhpParser\Node\Expr\Variable;
99
use PHPStan\Analyser\Scope;
10-
use PHPStan\Broker\Broker;
10+
use PHPStan\Reflection\ReflectionProvider;
1111
use PHPStan\Rules\Rule;
1212
use PHPStan\Rules\RuleError;
1313
use PHPStan\Rules\RuleErrorBuilder;
@@ -30,10 +30,10 @@ final class AccessGlobalVariableWithinContextRule implements Rule
3030
'argc' => true,
3131
'argv' => true,
3232
];
33-
private Broker $broker;
33+
private ReflectionProvider $broker;
3434
private string $contextBaseClassOrInterface;
3535

36-
public function __construct(Broker $broker, string $contextBaseClassOrInterface)
36+
public function __construct(ReflectionProvider $broker, string $contextBaseClassOrInterface)
3737
{
3838
$this->broker = $broker;
3939
$this->contextBaseClassOrInterface = $contextBaseClassOrInterface;

lib/AccessStaticPropertyWithinModelContextRule.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use PhpParser\Node;
88
use PhpParser\Node\Expr\StaticPropertyFetch;
99
use PHPStan\Analyser\Scope;
10-
use PHPStan\Broker\Broker;
10+
use PHPStan\Reflection\ReflectionProvider;
1111
use PHPStan\Rules\Rule;
1212
use PHPStan\Rules\RuleError;
1313
use PHPStan\Rules\RuleErrorBuilder;
@@ -17,11 +17,11 @@
1717
*/
1818
final class AccessStaticPropertyWithinModelContextRule implements Rule
1919
{
20-
private Broker $broker;
20+
private ReflectionProvider $broker;
2121
private string $modelBaseClassOrInterface;
2222
private string $singletonAccessor;
2323

24-
public function __construct(Broker $broker, string $modelBaseClassOrInterface, string $singletonAccessor)
24+
public function __construct(ReflectionProvider $broker, string $modelBaseClassOrInterface, string $singletonAccessor)
2525
{
2626
$this->broker = $broker;
2727
$this->modelBaseClassOrInterface = $modelBaseClassOrInterface;

lib/ClassNotationRule.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use PhpParser\Node\Stmt\Interface_;
1111
use PhpParser\Node\Stmt\Trait_;
1212
use PHPStan\Analyser\Scope;
13-
use PHPStan\Broker\Broker;
13+
use PHPStan\Reflection\ReflectionProvider;
1414
use PHPStan\Rules\Rule;
1515
use PHPStan\Rules\RuleError;
1616
use PHPStan\Rules\RuleErrorBuilder;
@@ -20,9 +20,9 @@
2020
*/
2121
final class ClassNotationRule implements Rule
2222
{
23-
private Broker $broker;
23+
private ReflectionProvider $broker;
2424

25-
public function __construct(Broker $broker)
25+
public function __construct(ReflectionProvider $broker)
2626
{
2727
$this->broker = $broker;
2828
}

lib/PhpUnitFqcnAnnotationRule.php

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

77
use PhpParser\Node;
88
use PHPStan\Analyser\Scope;
9-
use PHPStan\Broker\Broker;
9+
use PHPStan\Reflection\ReflectionProvider;
1010
use PHPStan\Rules\Rule;
1111
use PHPStan\Rules\RuleError;
1212
use PHPStan\Rules\RuleErrorBuilder;
@@ -16,12 +16,12 @@
1616
*/
1717
final class PhpUnitFqcnAnnotationRule implements Rule
1818
{
19-
private Broker $broker;
19+
private ReflectionProvider $broker;
2020

2121
/** @var bool[] */
2222
private array $alreadyParsedDocComments = [];
2323

24-
public function __construct(Broker $broker)
24+
public function __construct(ReflectionProvider $broker)
2525
{
2626
$this->broker = $broker;
2727
}

lib/StringToClassRule.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use PhpParser\Node;
88
use PhpParser\Node\Scalar\String_;
99
use PHPStan\Analyser\Scope;
10-
use PHPStan\Broker\Broker;
10+
use PHPStan\Reflection\ReflectionProvider;
1111
use PHPStan\Rules\Rule;
1212
use PHPStan\Rules\RuleError;
1313
use PHPStan\Rules\RuleErrorBuilder;
@@ -17,9 +17,9 @@
1717
*/
1818
final class StringToClassRule implements Rule
1919
{
20-
private Broker $broker;
20+
private ReflectionProvider $broker;
2121

22-
public function __construct(Broker $broker)
22+
public function __construct(ReflectionProvider $broker)
2323
{
2424
$this->broker = $broker;
2525
}

lib/SymfonyFilesystemRule.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use PhpParser\Node\Expr\FuncCall;
99
use PhpParser\Node\Name;
1010
use PHPStan\Analyser\Scope;
11-
use PHPStan\Broker\Broker;
11+
use PHPStan\Reflection\ReflectionProvider;
1212
use PHPStan\Rules\Rule;
1313
use PHPStan\Rules\RuleError;
1414
use PHPStan\Rules\RuleErrorBuilder;
@@ -38,9 +38,9 @@ final class SymfonyFilesystemRule implements Rule
3838
'file_put_contents' => ['dumpFile', 'appendToFile'],
3939
];
4040

41-
private Broker $broker;
41+
private ReflectionProvider $broker;
4242

43-
public function __construct(Broker $broker)
43+
public function __construct(ReflectionProvider $broker)
4444
{
4545
$this->broker = $broker;
4646
}

lib/SymfonyProcessRule.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use PhpParser\Node\Expr\FuncCall;
99
use PhpParser\Node\Name;
1010
use PHPStan\Analyser\Scope;
11-
use PHPStan\Broker\Broker;
11+
use PHPStan\Reflection\ReflectionProvider;
1212
use PHPStan\Rules\Rule;
1313
use PHPStan\Rules\RuleError;
1414
use PHPStan\Rules\RuleErrorBuilder;
@@ -30,9 +30,9 @@ final class SymfonyProcessRule implements Rule
3030
'system' => true,
3131
];
3232

33-
private Broker $broker;
33+
private ReflectionProvider $broker;
3434

35-
public function __construct(Broker $broker)
35+
public function __construct(ReflectionProvider $broker)
3636
{
3737
$this->broker = $broker;
3838
}

lib/UnusedVariableRule.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use PhpParser\Node\Name;
1515
use PhpParser\Node\Scalar\String_;
1616
use PHPStan\Analyser\Scope;
17-
use PHPStan\Broker\Broker;
17+
use PHPStan\Reflection\ReflectionProvider;
1818
use PHPStan\Rules\Rule;
1919
use PHPStan\Rules\RuleError;
2020
use PHPStan\Rules\RuleErrorBuilder;
@@ -37,7 +37,7 @@ final class UnusedVariableRule implements Rule
3737
];
3838

3939
public function __construct(
40-
private readonly Broker $broker,
40+
private readonly ReflectionProvider $broker,
4141
) {}
4242

4343
public function getNodeType(): string
@@ -157,7 +157,7 @@ private function captureVariablesUsedByCompactFunction(Node $node, Scope $scope,
157157
if (! $this->isCompactFunction($node, $scope)) {
158158
return;
159159
}
160-
// @phpstan-ignore-next-line: $node->args is valid due to $node being instanceof FuncCall
160+
161161
foreach ($node->args as $arg) {
162162
if ($arg->value instanceof String_) {
163163
$usedVariables[$arg->value->value] = true;

phpstan-baseline.neon

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,55 @@
11
parameters:
22
ignoreErrors:
33
-
4-
message: "#^Doing instanceof PHPStan\\\\Type\\\\ConstantScalarType is error\\-prone and deprecated\\. Use Type\\:\\:isConstantScalarValue\\(\\) or Type\\:\\:getConstantScalarTypes\\(\\) or Type\\:\\:getConstantScalarValues\\(\\) instead\\.$#"
4+
message: '#^Doing instanceof PHPStan\\Type\\ConstantScalarType is error\-prone and deprecated\. Use Type\:\:isConstantScalarValue\(\) or Type\:\:getConstantScalarTypes\(\) or Type\:\:getConstantScalarValues\(\) instead\.$#'
5+
identifier: phpstanApi.instanceofType
56
count: 1
67
path: lib/NotNow/NoRelativeDateTimeInterfaceRule.php
78

89
-
9-
message: "#^Doing instanceof PHPStan\\\\Type\\\\TypeWithClassName is error\\-prone and deprecated\\. Use Type\\:\\:getObjectClassNames\\(\\) or Type\\:\\:getObjectClassReflections\\(\\) instead\\.$#"
10+
message: '#^Doing instanceof PHPStan\\Type\\TypeWithClassName is error\-prone and deprecated\. Use Type\:\:getObjectClassNames\(\) or Type\:\:getObjectClassReflections\(\) instead\.$#'
11+
identifier: phpstanApi.instanceofType
1012
count: 1
1113
path: lib/NotNow/NoRelativeDateTimeInterfaceRule.php
1214

1315
-
14-
message: "#^Doing instanceof PHPStan\\\\Type\\\\ConstantScalarType is error\\-prone and deprecated\\. Use Type\\:\\:isConstantScalarValue\\(\\) or Type\\:\\:getConstantScalarTypes\\(\\) or Type\\:\\:getConstantScalarValues\\(\\) instead\\.$#"
16+
message: '#^Doing instanceof PHPStan\\Type\\ConstantScalarType is error\-prone and deprecated\. Use Type\:\:isConstantScalarValue\(\) or Type\:\:getConstantScalarTypes\(\) or Type\:\:getConstantScalarValues\(\) instead\.$#'
17+
identifier: phpstanApi.instanceofType
1518
count: 1
1619
path: lib/NotNow/NoRelativeStrtotimeRule.php
1720

1821
-
19-
message: "#^Cannot call method getAttribute\\(\\) on mixed\\.$#"
22+
message: '#^Access to an undefined property PhpParser\\Node\:\:\$args\.$#'
23+
identifier: property.notFound
24+
count: 1
25+
path: lib/UnusedVariableRule.php
26+
27+
-
28+
message: '#^Argument of an invalid type mixed supplied for foreach, only iterables are supported\.$#'
29+
identifier: foreach.nonIterable
30+
count: 1
31+
path: lib/UnusedVariableRule.php
32+
33+
-
34+
message: '#^Cannot access property \$value on mixed\.$#'
35+
identifier: property.nonObject
36+
count: 2
37+
path: lib/UnusedVariableRule.php
38+
39+
-
40+
message: '#^Cannot call method getAttribute\(\) on mixed\.$#'
41+
identifier: method.nonObject
42+
count: 1
43+
path: lib/UnusedVariableRule.php
44+
45+
-
46+
message: '#^Parameter \#1 \$line of method PHPStan\\Rules\\RuleErrorBuilder\<PHPStan\\Rules\\RuleError\>\:\:line\(\) expects int, mixed given\.$#'
47+
identifier: argument.type
48+
count: 1
49+
path: lib/UnusedVariableRule.php
50+
51+
-
52+
message: '#^Parameter \#2 \.\.\.\$values of function sprintf expects bool\|float\|int\|string\|null, mixed given\.$#'
53+
identifier: argument.type
2054
count: 1
2155
path: lib/UnusedVariableRule.php

0 commit comments

Comments
 (0)