Skip to content

Commit

Permalink
Upgrade to PHPStan 2.0 (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
Slamdunk authored Nov 11, 2024
1 parent 3211cbc commit df4a94b
Show file tree
Hide file tree
Showing 18 changed files with 73 additions and 39 deletions.
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
],
"require": {
"php": "~8.3.0 || ~8.4.0",
"phpstan/phpstan": "^1.12.9"
"phpstan/phpstan": "^2"
},
"require-dev": {
"nette/di": "^3.2.3",
"nette/neon": "^3.4.4",
"nikic/php-parser": "^4.19.2 || ^5.2.0",
"phpstan/phpstan-phpunit": "^1.4.0",
"nikic/php-parser": "^4.19.2 || ^5.3.1",
"phpstan/phpstan-phpunit": "^2",
"phpunit/phpunit": "^11.4.3",
"slam/php-cs-fixer-extensions": "^3.12.0"
},
Expand Down
6 changes: 3 additions & 3 deletions lib/AccessGlobalVariableWithinContextRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use PhpParser\Node;
use PhpParser\Node\Expr\Variable;
use PHPStan\Analyser\Scope;
use PHPStan\Broker\Broker;
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleError;
use PHPStan\Rules\RuleErrorBuilder;
Expand All @@ -30,10 +30,10 @@ final class AccessGlobalVariableWithinContextRule implements Rule
'argc' => true,
'argv' => true,
];
private Broker $broker;
private ReflectionProvider $broker;
private string $contextBaseClassOrInterface;

public function __construct(Broker $broker, string $contextBaseClassOrInterface)
public function __construct(ReflectionProvider $broker, string $contextBaseClassOrInterface)
{
$this->broker = $broker;
$this->contextBaseClassOrInterface = $contextBaseClassOrInterface;
Expand Down
6 changes: 3 additions & 3 deletions lib/AccessStaticPropertyWithinModelContextRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use PhpParser\Node;
use PhpParser\Node\Expr\StaticPropertyFetch;
use PHPStan\Analyser\Scope;
use PHPStan\Broker\Broker;
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleError;
use PHPStan\Rules\RuleErrorBuilder;
Expand All @@ -17,11 +17,11 @@
*/
final class AccessStaticPropertyWithinModelContextRule implements Rule
{
private Broker $broker;
private ReflectionProvider $broker;
private string $modelBaseClassOrInterface;
private string $singletonAccessor;

public function __construct(Broker $broker, string $modelBaseClassOrInterface, string $singletonAccessor)
public function __construct(ReflectionProvider $broker, string $modelBaseClassOrInterface, string $singletonAccessor)
{
$this->broker = $broker;
$this->modelBaseClassOrInterface = $modelBaseClassOrInterface;
Expand Down
6 changes: 3 additions & 3 deletions lib/ClassNotationRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use PhpParser\Node\Stmt\Interface_;
use PhpParser\Node\Stmt\Trait_;
use PHPStan\Analyser\Scope;
use PHPStan\Broker\Broker;
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleError;
use PHPStan\Rules\RuleErrorBuilder;
Expand All @@ -20,9 +20,9 @@
*/
final class ClassNotationRule implements Rule
{
private Broker $broker;
private ReflectionProvider $broker;

public function __construct(Broker $broker)
public function __construct(ReflectionProvider $broker)
{
$this->broker = $broker;
}
Expand Down
6 changes: 3 additions & 3 deletions lib/PhpUnitFqcnAnnotationRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use PhpParser\Node;
use PHPStan\Analyser\Scope;
use PHPStan\Broker\Broker;
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleError;
use PHPStan\Rules\RuleErrorBuilder;
Expand All @@ -16,12 +16,12 @@
*/
final class PhpUnitFqcnAnnotationRule implements Rule
{
private Broker $broker;
private ReflectionProvider $broker;

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

public function __construct(Broker $broker)
public function __construct(ReflectionProvider $broker)
{
$this->broker = $broker;
}
Expand Down
6 changes: 3 additions & 3 deletions lib/StringToClassRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use PhpParser\Node;
use PhpParser\Node\Scalar\String_;
use PHPStan\Analyser\Scope;
use PHPStan\Broker\Broker;
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleError;
use PHPStan\Rules\RuleErrorBuilder;
Expand All @@ -17,9 +17,9 @@
*/
final class StringToClassRule implements Rule
{
private Broker $broker;
private ReflectionProvider $broker;

public function __construct(Broker $broker)
public function __construct(ReflectionProvider $broker)
{
$this->broker = $broker;
}
Expand Down
6 changes: 3 additions & 3 deletions lib/SymfonyFilesystemRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Name;
use PHPStan\Analyser\Scope;
use PHPStan\Broker\Broker;
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleError;
use PHPStan\Rules\RuleErrorBuilder;
Expand Down Expand Up @@ -38,9 +38,9 @@ final class SymfonyFilesystemRule implements Rule
'file_put_contents' => ['dumpFile', 'appendToFile'],
];

private Broker $broker;
private ReflectionProvider $broker;

public function __construct(Broker $broker)
public function __construct(ReflectionProvider $broker)
{
$this->broker = $broker;
}
Expand Down
6 changes: 3 additions & 3 deletions lib/SymfonyProcessRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Name;
use PHPStan\Analyser\Scope;
use PHPStan\Broker\Broker;
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleError;
use PHPStan\Rules\RuleErrorBuilder;
Expand All @@ -30,9 +30,9 @@ final class SymfonyProcessRule implements Rule
'system' => true,
];

private Broker $broker;
private ReflectionProvider $broker;

public function __construct(Broker $broker)
public function __construct(ReflectionProvider $broker)
{
$this->broker = $broker;
}
Expand Down
6 changes: 3 additions & 3 deletions lib/UnusedVariableRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use PhpParser\Node\Name;
use PhpParser\Node\Scalar\String_;
use PHPStan\Analyser\Scope;
use PHPStan\Broker\Broker;
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleError;
use PHPStan\Rules\RuleErrorBuilder;
Expand All @@ -37,7 +37,7 @@ final class UnusedVariableRule implements Rule
];

public function __construct(
private readonly Broker $broker,
private readonly ReflectionProvider $broker,
) {}

public function getNodeType(): string
Expand Down Expand Up @@ -157,7 +157,7 @@ private function captureVariablesUsedByCompactFunction(Node $node, Scope $scope,
if (! $this->isCompactFunction($node, $scope)) {
return;
}
// @phpstan-ignore-next-line: $node->args is valid due to $node being instanceof FuncCall

foreach ($node->args as $arg) {
if ($arg->value instanceof String_) {
$usedVariables[$arg->value->value] = true;
Expand Down
42 changes: 38 additions & 4 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,21 +1,55 @@
parameters:
ignoreErrors:
-
message: "#^Doing instanceof PHPStan\\\\Type\\\\ConstantScalarType is error\\-prone and deprecated\\. Use Type\\:\\:isConstantScalarValue\\(\\) or Type\\:\\:getConstantScalarTypes\\(\\) or Type\\:\\:getConstantScalarValues\\(\\) instead\\.$#"
message: '#^Doing instanceof PHPStan\\Type\\ConstantScalarType is error\-prone and deprecated\. Use Type\:\:isConstantScalarValue\(\) or Type\:\:getConstantScalarTypes\(\) or Type\:\:getConstantScalarValues\(\) instead\.$#'
identifier: phpstanApi.instanceofType
count: 1
path: lib/NotNow/NoRelativeDateTimeInterfaceRule.php

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

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

-
message: "#^Cannot call method getAttribute\\(\\) on mixed\\.$#"
message: '#^Access to an undefined property PhpParser\\Node\:\:\$args\.$#'
identifier: property.notFound
count: 1
path: lib/UnusedVariableRule.php

-
message: '#^Argument of an invalid type mixed supplied for foreach, only iterables are supported\.$#'
identifier: foreach.nonIterable
count: 1
path: lib/UnusedVariableRule.php

-
message: '#^Cannot access property \$value on mixed\.$#'
identifier: property.nonObject
count: 2
path: lib/UnusedVariableRule.php

-
message: '#^Cannot call method getAttribute\(\) on mixed\.$#'
identifier: method.nonObject
count: 1
path: lib/UnusedVariableRule.php

-
message: '#^Parameter \#1 \$line of method PHPStan\\Rules\\RuleErrorBuilder\<PHPStan\\Rules\\RuleError\>\:\:line\(\) expects int, mixed given\.$#'
identifier: argument.type
count: 1
path: lib/UnusedVariableRule.php

-
message: '#^Parameter \#2 \.\.\.\$values of function sprintf expects bool\|float\|int\|string\|null, mixed given\.$#'
identifier: argument.type
count: 1
path: lib/UnusedVariableRule.php
2 changes: 1 addition & 1 deletion tests/AccessGlobalVariableWithinContextRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ protected function setUp(): void

protected function getRule(): Rule
{
$broker = $this->createBroker();
$broker = $this->createReflectionProvider();

return new AccessGlobalVariableWithinContextRule($broker, $this->contextBaseClassOrInterface);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/AccessStaticPropertyWithinModelContextRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ protected function setUp(): void

protected function getRule(): Rule
{
$broker = $this->createBroker();
$broker = $this->createReflectionProvider();

return new AccessStaticPropertyWithinModelContextRule(
$broker,
Expand Down
2 changes: 1 addition & 1 deletion tests/ClassNotationRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ final class ClassNotationRuleTest extends RuleTestCase
{
protected function getRule(): Rule
{
$broker = $this->createBroker();
$broker = $this->createReflectionProvider();

return new ClassNotationRule($broker);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/PhpUnitFqcnAnnotationRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ final class PhpUnitFqcnAnnotationRuleTest extends RuleTestCase
{
protected function getRule(): Rule
{
$broker = $this->createBroker();
$broker = $this->createReflectionProvider();

return new PhpUnitFqcnAnnotationRule($broker);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/StringToClassRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ final class StringToClassRuleTest extends RuleTestCase
{
protected function getRule(): Rule
{
$broker = $this->createBroker();
$broker = $this->createReflectionProvider();

return new StringToClassRule($broker);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/SymfonyFilesystemRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ final class SymfonyFilesystemRuleTest extends RuleTestCase
{
protected function getRule(): Rule
{
$broker = $this->createBroker();
$broker = $this->createReflectionProvider();

return new SymfonyFilesystemRule($broker);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/SymfonyProcessRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ final class SymfonyProcessRuleTest extends RuleTestCase
{
protected function getRule(): Rule
{
$broker = $this->createBroker();
$broker = $this->createReflectionProvider();

return new SymfonyProcessRule($broker);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/UnusedVariableRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ final class UnusedVariableRuleTest extends RuleTestCase
{
protected function getRule(): Rule
{
$broker = $this->createBroker();
$broker = $this->createReflectionProvider();

return new UnusedVariableRule($broker);
}
Expand Down

0 comments on commit df4a94b

Please sign in to comment.