Skip to content

Commit d73a34a

Browse files
authored
Update to PHPStan 2.x and Rector 2.x (#9)
* Raise min PHP version to 7.4 * Update to PHPStan 2.x and Rector 2.x * PHPStan upgrade-guide: checkGenericClassInNonGenericObjectType * Fix alwaysTrue errors * Fix RuleTestCase parameter types * Remove use of `ParametersAcceptorSelector::selectSingle()` * Fix remaining PHPStan errors * Use `ParserFactory->createForHostVersion()` * Fix PHP 7.2 leftovers
1 parent 1c9472c commit d73a34a

File tree

14 files changed

+27
-26
lines changed

14 files changed

+27
-26
lines changed

.github/workflows/downgraded_release.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ jobs:
2121

2222
- uses: "ramsey/composer-install@v2"
2323

24-
# downgrade /src to PHP 7.2
25-
- run: vendor/bin/rector process src --config build/rector-downgrade-php-72.php --ansi
24+
# downgrade /src to PHP 7.4
25+
- run: vendor/bin/rector process src --config build/rector-downgrade-php-74.php --ansi
2626
- run: vendor/bin/ecs check src --fix --ansi
2727

28-
# copy PHP 7.2 composer
29-
- run: cp build/composer-php-72.json composer.json
28+
# copy PHP 7.4 composer
29+
- run: cp build/composer-php-74.json composer.json
3030

3131
# clear the dev files
3232
- run: rm -rf build .github tests stubs ecs.php phpstan.neon phpunit.xml
@@ -43,7 +43,7 @@ jobs:
4343
run: |
4444
# separate a "git add" to add untracked (new) files too
4545
git add --all
46-
git commit -m "release PHP 7.2 downgraded"
46+
git commit -m "release PHP 7.4 downgraded"
4747
4848
# force push tag, so there is only 1 version
4949
git tag "${GITHUB_REF#refs/tags/}" --force

.github/workflows/various_php_install.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ jobs:
1313
fail-fast: false
1414
matrix:
1515
php:
16-
- 7.2
1716
- 7.4
1817
- 8.0
1918
- 8.1

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ How to keep **cognitive complexity on 1**? Read [Keep Cognitive Complexity Low w
3737
composer require tomasvotruba/cognitive-complexity --dev
3838
```
3939

40-
The package is available on PHP 7.2-8.1 versions in tagged releases.
40+
The package is available on PHP 7.4-8.1 versions in tagged releases.
4141

4242
<br>
4343

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
"description": "PHPStan rules to measure cognitive complexity of your classes and methods",
55
"license": "MIT",
66
"require": {
7-
"php": "^7.2 || ^8.0",
8-
"phpstan/phpstan": "^1.10"
7+
"php": "^7.4 || ^8.0",
8+
"phpstan/phpstan": "^2"
99
},
1010
"autoload": {
1111
"psr-4": {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
use Rector\Set\ValueObject\DowngradeLevelSetList;
77

88
return static function (RectorConfig $rectorConfig): void {
9-
$rectorConfig->sets([DowngradeLevelSetList::DOWN_TO_PHP_72]);
9+
$rectorConfig->sets([DowngradeLevelSetList::DOWN_TO_PHP_74]);
1010
};

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
"license": "MIT",
66
"require": {
77
"php": "^8.2",
8-
"phpstan/phpstan": "^1.10.50",
9-
"nikic/php-parser": "^4"
8+
"phpstan/phpstan": "^2.0",
9+
"nikic/php-parser": "^5"
1010
},
1111
"require-dev": {
1212
"phpstan/extension-installer": "^1.3",
1313
"phpunit/phpunit": "^10.3",
1414
"symplify/easy-coding-standard": "^12.0",
15-
"rector/rector": "^0.18",
15+
"rector/rector": "^2",
1616
"tracy/tracy": "^2.9",
1717
"php-parallel-lint/php-parallel-lint": "^1.3"
1818
},

phpstan.neon

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ parameters:
1313
- src
1414
- tests
1515

16-
checkGenericClassInNonGenericObjectType: false
17-
1816
excludePaths:
1917
- "*/Fixture/*"
2018
- "*/Source/*"
2119

2220
ignoreErrors:
21+
- identifier: missingType.generics
22+
2323
# skip as always string
2424
- '#Parameter \#1 \$currentWorkingDirectory of class PHPStan\\DependencyInjection\\ContainerFactory constructor expects string, string\|false given#'

src/ClassReflectionParser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
public function __construct()
2020
{
2121
$parserFactory = new ParserFactory();
22-
$this->phpParser = $parserFactory->create(ParserFactory::PREFER_PHP7);
22+
$this->phpParser = $parserFactory->createForHostVersion();
2323

2424
$this->nodeFinder = new NodeFinder();
2525
}

src/NodeAnalyzer/ComplexityAffectingNodeFinder.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use PhpParser\Node\Expr;
99
use PhpParser\Node\Expr\BinaryOp\BooleanAnd;
1010
use PhpParser\Node\Expr\Ternary;
11-
use PhpParser\Node\Identifier;
1211
use PhpParser\Node\Stmt;
1312
use PhpParser\Node\Stmt\Break_;
1413
use PhpParser\Node\Stmt\Catch_;
@@ -71,12 +70,14 @@ public function isBreakingNode(Node $node): bool
7170
// B1. goto LABEL, break LABEL, continue LABEL
7271
if ($this->isInstanceOf($node, self::BREAKING_NODE_TYPES)) {
7372
// skip empty breaks
74-
/** @var Goto_|Break_|Continue_ $node */
75-
if ($node instanceof Goto_ && $node->name instanceof Identifier) {
73+
if ($node instanceof Goto_) {
7674
return true;
7775
}
7876

79-
if (($node instanceof Break_ || $node instanceof Continue_) && $node->num instanceof Expr) {
77+
if (
78+
($node instanceof Break_ || $node instanceof Continue_)
79+
&& $node->num instanceof Expr
80+
) {
8081
return true;
8182
}
8283
}

src/Rules/ClassDependencyTreeRule.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
use PHPStan\Reflection\ParametersAcceptorSelector;
1414
use PHPStan\Rules\Rule;
1515
use PHPStan\Rules\RuleErrorBuilder;
16-
use PHPStan\Type\TypeWithClassName;
1716
use TomasVotruba\CognitiveComplexity\AstCognitiveComplexityAnalyzer;
1817
use TomasVotruba\CognitiveComplexity\ClassReflectionParser;
1918
use TomasVotruba\CognitiveComplexity\Configuration;
@@ -70,7 +69,9 @@ public function processNode(Node $node, Scope $scope): array
7069

7170
$extendedMethodReflection = $classReflection->getConstructor();
7271

73-
$parametersAcceptorWithPhpDocs = ParametersAcceptorSelector::selectSingle(
72+
$parametersAcceptorWithPhpDocs = ParametersAcceptorSelector::selectFromArgs(
73+
$scope,
74+
[],
7475
$extendedMethodReflection->getVariants()
7576
);
7677

0 commit comments

Comments
 (0)