Skip to content

Commit 19d882e

Browse files
samsonasikzonuexe
andauthored
Allow Rector 2.0 (#145)
* Temporarily remove packages that are not compatible with PHPStan 2.0 * Make rules use RuleErrorBuilder * Skip tests that depend on Rector as incomplete * Add PhpParser\PrettyPrinter\Standard to DI config file * Comment out rules that are not PHPStan 2.0 compatible * Temporarily disable steps that are not compatible with PHPStan 2.0 * Disable symplify's own error-format * fixup! Make rules use RuleErrorBuilder * fixup! Temporarily remove packages that are not compatible with PHPStan 2.0 * Revert "Temporarily disable steps that are not compatible with PHPStan 2.0" This reverts commit 18efdf5. * Add Rule identifier * fixup! Skip tests that depend on Rector as incomplete * fixup! Make rules use RuleErrorBuilder * Allow Rector 2 * update downgrade script * update downgrade script * update downgrade script * update downgrade script * fix --------- Co-authored-by: USAMI Kenta <[email protected]>
1 parent 7ffd96d commit 19d882e

File tree

47 files changed

+188
-202
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+188
-202
lines changed

.github/workflows/bare_run.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
strategy:
1313
fail-fast: false
1414
matrix:
15-
php_version: ['7.2', '7.4', '8.0', '8.2']
15+
php_version: ['7.4', '8.0', '8.2']
1616

1717
steps:
1818
- uses: actions/checkout@v3

.github/workflows/downgraded_release.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ name: Downgraded Release
33
on:
44
push:
55
tags:
6-
# avoid infinite looping, skip tags that ends with ".72"
6+
# avoid infinite looping, skip tags that ends with ".74"
77
# see https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#example-including-and-excluding-branches
88
- '*'
9-
- '!**.72'
9+
- '!**.74'
1010

1111
jobs:
1212
downgrade_release:
@@ -33,13 +33,13 @@ jobs:
3333
- run: mkdir rector-local
3434
- run: composer require rector/rector:^0.17.1 --working-dir rector-local --ansi
3535

36-
# downgrade to PHP 7.2
37-
- run: rector-local/vendor/bin/rector process src config --config build/rector-downgrade-php-72.php --ansi
36+
# downgrade to PHP 7.4
37+
- run: rector-local/vendor/bin/rector process src config --config build/rector-downgrade-php-74.php --ansi
3838

3939
# clear the dev files
4040
- run: rm -rf tests rector-local ecs.php phpstan.neon phpunit.xml .editorconfig
4141

42-
# copy PHP 7.2 composer + workflows
42+
# copy PHP 7.4 composer + workflows
4343
- run: cp -r build/target-repository/. .
4444

4545
# clear the dev files
@@ -57,7 +57,7 @@ jobs:
5757
run: |
5858
# separate a "git add" to add untracked (new) files too
5959
git add --all
60-
git commit -m "release PHP 7.2 downgraded"
60+
git commit -m "release PHP 7.4 downgraded"
6161
6262
# force push tag, so there is only 1 version
6363
git tag "${GITHUB_REF#refs/tags/}" --force
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
return static function (RectorConfig $rectorConfig): void {
1212
$rectorConfig->parallel();
1313

14-
$rectorConfig->sets([DowngradeLevelSetList::DOWN_TO_PHP_72]);
14+
$rectorConfig->sets([DowngradeLevelSetList::DOWN_TO_PHP_74]);
1515

1616
$rectorConfig->ruleWithConfiguration(RemoveInterfacesRector::class, [
1717
DocumentedRuleInterface::class,

build/target-repository/.github/workflows/standalone_install.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
strategy:
1010
fail-fast: false
1111
matrix:
12-
php_version: ['7.2', '7.3', '7.4', '8.0']
12+
php_version: ['7.4', '8.0']
1313

1414
steps:
1515
# prepare empty composer.json that allows the phpstan extension plugin

build/target-repository/composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
"description": "Set of Symplify rules for PHPStan",
55
"license": "MIT",
66
"require": {
7-
"php": "^7.2|^8.0",
7+
"php": "^7.4|^8.0",
88
"nette/utils": "^3.2.9 || ^4.0",
9-
"phpstan/phpstan": "^1.10.30",
9+
"phpstan/phpstan": "^2.0",
1010
"webmozart/assert": "^1.11"
1111
},
1212
"autoload": {

composer.json

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,18 @@
77
"php": ">=8.1",
88
"nette/utils": "^3.2.9 || ^4.0",
99
"webmozart/assert": "^1.11",
10-
"phpstan/phpstan": "^1.11",
10+
"phpstan/phpstan": "^2.0",
1111
"symplify/rule-doc-generator-contracts": "^11.2"
1212
},
1313
"require-dev": {
14-
"nikic/php-parser": "^4.19",
15-
"symplify/phpstan-extensions": "^11.4",
14+
"nikic/php-parser": "^5.0",
1615
"symplify/rule-doc-generator": "^12.2",
1716
"phpunit/phpunit": "^10.5",
1817
"symfony/framework-bundle": "6.1.*",
19-
"rector/rector": "^1.2.3",
2018
"symplify/easy-coding-standard": "^12.3",
21-
"phpstan/extension-installer": "^1.4",
22-
"tomasvotruba/class-leak": "^0.2",
23-
"tomasvotruba/unused-public": "^0.3.10",
24-
"tomasvotruba/type-coverage": "^0.3.1"
19+
"tomasvotruba/class-leak": "^1.2",
20+
"rector/rector": "^2.0",
21+
"phpstan/extension-installer": "^1.4"
2522
},
2623
"autoload": {
2724
"psr-4": {
@@ -36,10 +33,6 @@
3633
"stubs"
3734
],
3835
"files": [
39-
"tests/Rules/Rector/PhpUpgradeImplementsMinPhpVersionInterfaceRule/Fixture/SomePhpFeatureRector.php",
40-
"vendor/rector/rector/src/Contract/Rector/RectorInterface.php",
41-
"vendor/rector/rector/src/Contract/Rector/ConfigurableRectorInterface.php",
42-
"vendor/rector/rector/vendor/rector/rector-downgrade-php/src/Set/ValueObject/DowngradeSetList.php"
4336
]
4437
},
4538
"extra": {
@@ -58,7 +51,7 @@
5851
"scripts": {
5952
"check-cs": "vendor/bin/ecs check --ansi",
6053
"fix-cs": "vendor/bin/ecs check --fix --ansi",
61-
"phpstan": "vendor/bin/phpstan analyse --ansi --error-format symplify",
54+
"phpstan": "vendor/bin/phpstan analyse --ansi",
6255
"rector": "vendor/bin/rector process --dry-run --ansi",
6356
"docs": "vendor/bin/rule-doc-generator generate src --readme --ansi"
6457
}

phpstan.neon

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ includes:
33
- config/naming-rules.neon
44

55
parameters:
6+
treatPhpDocTypesAsCertain: false
7+
68
level: 8
79

810
paths:
@@ -20,15 +22,15 @@ parameters:
2022
- */Fixture/*
2123

2224
# https://github.com/TomasVotruba/unused-public
23-
unused_public:
24-
methods: true
25-
properties: true
26-
constants: true
25+
# unused_public:
26+
# methods: true
27+
# properties: true
28+
# constants: true
2729

28-
type_coverage:
29-
return: 99
30-
param: 99
31-
property: 99
30+
# type_coverage:
31+
# return: 99
32+
# param: 99
33+
# property: 99
3234

3335
ignoreErrors:
3436
# needless generics
@@ -38,8 +40,6 @@ parameters:
3840

3941
- '#Method Symplify\\PHPStanRules\\Reflection\\ReflectionParser\:\:parseNativeClassReflection\(\) has parameter \$reflectionClass with generic class ReflectionClass but does not specify its types\: T#'
4042

41-
- '#Method Symplify\\PHPStanRules\\NodeFinder\\TypeAwareNodeFinder\:\:findFirstInstanceOf\(\) should return \(TNode of PhpParser\\Node\)\|null but returns PhpParser\\Node\|null#'
42-
4343
# overly detailed
4444
- '#Class Symplify\\PHPStanRules\\(.*?) extends generic class PHPStan\\Testing\\RuleTestCase but does not specify its types\: TRule#'
4545
- '#Method Symplify\\PHPStanRules\\(.*?)\:\:getRule\(\) return type with generic interface PHPStan\\Rules\\Rule does not specify its types\: TNodeType#'
@@ -50,5 +50,26 @@ parameters:
5050
# overly detailed
5151
- '#Class Symplify\\PHPStanRules\\Collector\\(.*?) implements generic interface PHPStan\\Collectors\\Collector but does not specify its types\: TNodeType, TValue#'
5252

53-
# used in tests
54-
- '#Public constant "(.*?)\:\:ERROR_MESSAGE" is never used#'
53+
-
54+
identifier: argument.type
55+
56+
-
57+
identifier: phpstanApi.instanceofType
58+
59+
-
60+
identifier: return.type
61+
62+
-
63+
identifier: class.notFound
64+
65+
-
66+
identifier: phpstanApi.runtimeReflection
67+
68+
-
69+
identifier: phpstanApi.instanceofAssumption
70+
71+
-
72+
identifier: generics.wrongParent
73+
74+
-
75+
identifier: method.childReturnType

src/Reflection/ReflectionParser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function __construct(
3131
private readonly TypeAwareNodeFinder $typeAwareNodeFinder
3232
) {
3333
$parserFactory = new ParserFactory();
34-
$this->parser = $parserFactory->create(ParserFactory::PREFER_PHP7);
34+
$this->parser = $parserFactory->createForNewestSupportedVersion();
3535
}
3636

3737
public function parseMethodReflection(ReflectionMethod|MethodReflection $reflectionMethod): ?ClassMethod

src/ReturnTypeExtension/NodeGetAttributeTypeExtension.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
use PhpParser\Node\Scalar\String_;
1414
use PHPStan\Analyser\Scope;
1515
use PHPStan\Reflection\MethodReflection;
16-
use PHPStan\Reflection\ParametersAcceptorSelector;
1716
use PHPStan\Type\DynamicMethodReturnTypeExtension;
1817
use PHPStan\Type\NullType;
1918
use PHPStan\Type\ObjectType;

src/Rules/AbstractSymplifyRule.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use PhpParser\Node;
88
use PHPStan\Analyser\Scope;
99
use PHPStan\Rules\Rule;
10-
use PHPStan\Rules\RuleError;
1110
use Symplify\PHPStanRules\Contract\ManyNodeRuleInterface;
1211
use Symplify\RuleDocGenerator\Contract\DocumentedRuleInterface;
1312

@@ -24,9 +23,6 @@ public function getNodeType(): string
2423
return Node::class;
2524
}
2625

27-
/**
28-
* @return string[]|RuleError[]
29-
*/
3026
public function processNode(Node $node, Scope $scope): array
3127
{
3228
if ($this->shouldSkipNode($node)) {

0 commit comments

Comments
 (0)