Skip to content

Commit aefdbff

Browse files
authored
Require PHPStan 2.0 (#274)
1 parent 4a8e922 commit aefdbff

32 files changed

+163
-216
lines changed

composer.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,17 @@
1111
],
1212
"require": {
1313
"php": "^7.4 || ^8.0",
14-
"phpstan/phpstan": "^1.12.5"
14+
"phpstan/phpstan": "^2.0"
1515
},
1616
"require-dev": {
1717
"editorconfig-checker/editorconfig-checker": "^10.6.0",
1818
"ergebnis/composer-normalize": "^2.28",
1919
"nette/neon": "^3.3.1",
20-
"phpstan/phpstan-deprecation-rules": "^1.2",
21-
"phpstan/phpstan-phpunit": "^1.4.0",
22-
"phpstan/phpstan-strict-rules": "^1.6.0",
20+
"phpstan/phpstan-deprecation-rules": "^2.0",
21+
"phpstan/phpstan-phpunit": "^2.0",
22+
"phpstan/phpstan-strict-rules": "^2.0",
2323
"phpunit/phpunit": "^9.5.20",
2424
"shipmonk/composer-dependency-analyser": "^1.3.0",
25-
"shipmonk/dead-code-detector": "^0.2.1",
2625
"shipmonk/name-collision-detector": "^2.0.0",
2726
"slevomat/coding-standard": "^8.0.1"
2827
},

composer.lock

Lines changed: 61 additions & 130 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

phpstan.neon.dist

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ includes:
55
- ./vendor/phpstan/phpstan-phpunit/extension.neon
66
- ./vendor/phpstan/phpstan-phpunit/rules.neon
77
- ./vendor/phpstan/phpstan-deprecation-rules/rules.neon
8-
- ./vendor/shipmonk/dead-code-detector/rules.neon
98
- ./rules.neon
109

1110
parameters:

rules.neon

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,8 @@ services:
339339
allowedCheckedExceptionCallables: %shipmonkRules.forbidCheckedExceptionInCallable.allowedCheckedExceptionCallables%
340340
-
341341
class: ShipMonk\PHPStan\Rule\ForbidCheckedExceptionInYieldingMethodRule
342+
arguments:
343+
exceptionTypeResolver: @PHPStan\Rules\Exceptions\DefaultExceptionTypeResolver
342344
-
343345
class: ShipMonk\PHPStan\Rule\ForbidCustomFunctionsRule
344346
arguments:

src/Rule/EnforceListReturnRule.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use PHPStan\Rules\IdentifierRuleError;
1111
use PHPStan\Rules\Rule;
1212
use PHPStan\Rules\RuleErrorBuilder;
13-
use PHPStan\Type\Accessory\AccessoryArrayListType;
1413
use PHPStan\Type\VerbosityLevel;
1514
use function count;
1615

@@ -31,10 +30,6 @@ public function getNodeType(): string
3130
*/
3231
public function processNode(Node $node, Scope $scope): array
3332
{
34-
if (AccessoryArrayListType::isListTypeEnabled() === false) {
35-
return [];
36-
}
37-
3833
$methodReflection = $scope->getFunction();
3934

4035
if ($methodReflection === null || $node instanceof ClosureReturnStatementsNode) {

src/Rule/EnforceNativeReturnTypehintRule.php

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

55
use Generator;
66
use PhpParser\Node;
7-
use PhpParser\Node\Stmt\Throw_;
7+
use PhpParser\Node\Expr\Throw_;
8+
use PhpParser\Node\Stmt\Expression;
89
use PHPStan\Analyser\Scope;
910
use PHPStan\Node\ReturnStatementsNode;
1011
use PHPStan\Php\PhpVersion;
@@ -328,7 +329,10 @@ private function alwaysThrowsException(ReturnStatementsNode $node): bool
328329
$exitPoints = $node->getStatementResult()->getExitPoints();
329330

330331
foreach ($exitPoints as $exitPoint) {
331-
if (!$exitPoint->getStatement() instanceof Throw_) {
332+
$statement = $exitPoint->getStatement();
333+
$isThrow = $statement instanceof Expression && $statement->expr instanceof Throw_;
334+
335+
if (!$isThrow) {
332336
return false;
333337
}
334338
}

src/Rule/ForbidCheckedExceptionInCallableRule.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@
2626
use PHPStan\Node\FunctionCallableNode;
2727
use PHPStan\Node\MethodCallableNode;
2828
use PHPStan\Node\StaticMethodCallableNode;
29+
use PHPStan\Reflection\ExtendedParameterReflection;
2930
use PHPStan\Reflection\FunctionReflection;
3031
use PHPStan\Reflection\MethodReflection;
3132
use PHPStan\Reflection\ParameterReflection;
32-
use PHPStan\Reflection\ParameterReflectionWithPhpDocs;
3333
use PHPStan\Reflection\ParametersAcceptorSelector;
3434
use PHPStan\Reflection\ReflectionProvider;
3535
use PHPStan\Rules\Exceptions\DefaultExceptionTypeResolver;
@@ -239,7 +239,7 @@ public function processArrowFunction(
239239
$result = $this->nodeScopeResolver->processExprNode(
240240
new Expression($node->expr),
241241
$node->expr,
242-
$scope->enterArrowFunction($node),
242+
$scope->enterArrowFunction($node, null),
243243
static function (): void {
244244
},
245245
ExpressionContext::createDeep(),
@@ -354,7 +354,7 @@ private function checkClassExistence(
354354
*/
355355
private function isImmediatelyInvokedCallable(object $reflection, ?ParameterReflection $parameter): bool
356356
{
357-
if ($parameter instanceof ParameterReflectionWithPhpDocs) {
357+
if ($parameter instanceof ExtendedParameterReflection) {
358358
$parameterCallImmediately = $parameter->isImmediatelyInvokedCallable();
359359

360360
if ($parameterCallImmediately->maybe()) {

src/Rule/ForbidCheckedExceptionInYieldingMethodRule.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use PhpParser\Node;
66
use PHPStan\Analyser\Scope;
77
use PHPStan\Node\MethodReturnStatementsNode;
8-
use PHPStan\Rules\Exceptions\DefaultExceptionTypeResolver;
8+
use PHPStan\Rules\Exceptions\ExceptionTypeResolver;
99
use PHPStan\Rules\IdentifierRuleError;
1010
use PHPStan\Rules\Rule;
1111
use PHPStan\Rules\RuleErrorBuilder;
@@ -16,9 +16,9 @@
1616
class ForbidCheckedExceptionInYieldingMethodRule implements Rule
1717
{
1818

19-
private DefaultExceptionTypeResolver $exceptionTypeResolver;
19+
private ExceptionTypeResolver $exceptionTypeResolver;
2020

21-
public function __construct(DefaultExceptionTypeResolver $exceptionTypeResolver)
21+
public function __construct(ExceptionTypeResolver $exceptionTypeResolver)
2222
{
2323
$this->exceptionTypeResolver = $exceptionTypeResolver;
2424
}

src/Rule/ForbidFetchOnMixedRule.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
use PhpParser\Node\Expr\PropertyFetch;
1010
use PhpParser\Node\Expr\StaticPropertyFetch;
1111
use PhpParser\Node\Identifier;
12-
use PhpParser\PrettyPrinter\Standard;
1312
use PHPStan\Analyser\Scope;
13+
use PHPStan\Node\Printer\Printer;
1414
use PHPStan\Rules\IdentifierRuleError;
1515
use PHPStan\Rules\Rule;
1616
use PHPStan\Rules\RuleErrorBuilder;
@@ -25,11 +25,11 @@
2525
class ForbidFetchOnMixedRule implements Rule
2626
{
2727

28-
private Standard $printer;
28+
private Printer $printer;
2929

3030
private bool $checkExplicitMixed;
3131

32-
public function __construct(Standard $printer, bool $checkExplicitMixed)
32+
public function __construct(Printer $printer, bool $checkExplicitMixed)
3333
{
3434
$this->printer = $printer;
3535
$this->checkExplicitMixed = $checkExplicitMixed;

src/Rule/ForbidMethodCallOnMixedRule.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
use PhpParser\Node\Expr\MethodCall;
1010
use PhpParser\Node\Expr\StaticCall;
1111
use PhpParser\Node\Identifier;
12-
use PhpParser\PrettyPrinter\Standard;
1312
use PHPStan\Analyser\Scope;
13+
use PHPStan\Node\Printer\Printer;
1414
use PHPStan\Rules\IdentifierRuleError;
1515
use PHPStan\Rules\Rule;
1616
use PHPStan\Rules\RuleErrorBuilder;
@@ -24,11 +24,11 @@
2424
class ForbidMethodCallOnMixedRule implements Rule
2525
{
2626

27-
private Standard $printer;
27+
private Printer $printer;
2828

2929
private bool $checkExplicitMixed;
3030

31-
public function __construct(Standard $printer, bool $checkExplicitMixed)
31+
public function __construct(Printer $printer, bool $checkExplicitMixed)
3232
{
3333
$this->printer = $printer;
3434
$this->checkExplicitMixed = $checkExplicitMixed;

0 commit comments

Comments
 (0)