Skip to content

Commit c389a27

Browse files
authored
Bump to PHPStan 2 and PHPParser 5 (#6)
* Bump to PHPStan 2 and PHPParser 5 * bump php req * bump name
1 parent 9639ef9 commit c389a27

File tree

6 files changed

+18
-37
lines changed

6 files changed

+18
-37
lines changed

.github/workflows/tests.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
-
2222
uses: shivammathur/setup-php@v2
2323
with:
24-
php-version: 8.1
24+
php-version: 8.2
2525
coverage: none
2626

2727
- uses: "ramsey/composer-install@v1"

composer.json

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,16 @@
44
"license": "MIT",
55
"description": "Rector upgrades rules for PHP-Parser",
66
"require": {
7-
"php": ">=8.1"
7+
"php": ">=8.2"
88
},
99
"require-dev": {
1010
"phpstan/extension-installer": "^1.1",
1111
"phpunit/phpunit": "^10.0",
12-
"rector/phpstan-rules": "^0.6",
13-
"phpstan/phpstan": "^1.8.2",
14-
"symplify/phpstan-rules": "^11.1",
15-
"symplify/phpstan-extensions": "^11.1",
12+
"phpstan/phpstan": "^2.0",
1613
"symplify/easy-coding-standard": "^11.1",
17-
"symplify/rule-doc-generator": "^11.1",
1814
"rector/rector-src": "dev-main",
19-
"phpstan/phpstan-strict-rules": "^1.3",
20-
"phpstan/phpstan-webmozart-assert": "^1.2",
15+
"phpstan/phpstan-webmozart-assert": "^2.0",
2116
"symplify/vendor-patches": "^11.1",
22-
"rector/rector-debugging": "dev-main",
23-
"rector/rector-generator": "^0.6.13",
2417
"symplify/easy-ci": "11.2.0.72"
2518
},
2619
"autoload": {
@@ -34,13 +27,9 @@
3427
}
3528
},
3629
"scripts": {
37-
"phpstan": "vendor/bin/phpstan analyse --ansi --error-format symplify",
30+
"phpstan": "vendor/bin/phpstan analyse --ansi",
3831
"check-cs": "vendor/bin/ecs check --ansi",
39-
"fix-cs": "vendor/bin/ecs check --fix --ansi",
40-
"docs": [
41-
"vendor/bin/rule-doc-generator generate src --output-file docs/rector_rules_overview.md --ansi",
42-
"vendor/bin/ecs check-markdown docs/rector_rules_overview.md --ansi --fix"
43-
]
32+
"fix-cs": "vendor/bin/ecs check --fix --ansi"
4433
},
4534
"extra": {
4635
"enable-patching": true,

config/config.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,4 @@
55
use Rector\Config\RectorConfig;
66

77
return static function (RectorConfig $rectorConfig): void {
8-
$services = $rectorConfig->services();
9-
10-
$services->defaults()
11-
->public()
12-
->autowire()
13-
->autoconfigure();
14-
15-
$services->load('Rector\\PhpParser\\', __DIR__ . '/../src')
16-
->exclude([__DIR__ . '/../src/Set', __DIR__ . '/../src/Rector', __DIR__ . '/../src/ValueObject']);
178
};

easy-ci.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
use Rector\Core\Contract\Rector\RectorInterface;
5+
use Rector\Contract\Rector\RectorInterface;
66
use Symplify\EasyCI\Config\EasyCIConfig;
77

88
return static function (EasyCIConfig $easyCIConfig): void {

phpstan.neon

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
includes:
2-
- vendor/symplify/phpstan-rules/config/symplify-rules.neon
1+
#includes:
2+
# - vendor/symplify/phpstan-rules/config/symplify-rules.neon
33

44
parameters:
55
level: max
@@ -14,8 +14,3 @@ parameters:
1414
- *Source/*
1515

1616
ignoreErrors:
17-
- '#Parameter (.*?) of method (.*?)\:\:refactor\(\) should be contravariant with parameter \$node \(PhpParser\\Node\) of method Rector\\Core\\Contract\\Rector\\PhpRectorInterface\:\:refactor\(\)#'
18-
19-
-
20-
message: '#Attribute must have all names explicitly defined#'
21-
path: 'tests/*'

src/Rector/MethodCall/ParserFactoryRector.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
use PhpParser\Node\Name\FullyQualified;
1313
use PhpParser\Node\Scalar\String_;
1414
use PHPStan\Type\ObjectType;
15-
use Rector\Core\Rector\AbstractRector;
15+
use Rector\PhpParser\Node\Value\ValueResolver;
16+
use Rector\Rector\AbstractRector;
1617
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
1718
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
1819

@@ -23,6 +24,11 @@
2324
*/
2425
final class ParserFactoryRector extends AbstractRector
2526
{
27+
public function __construct(
28+
private readonly ValueResolver $valueResolver
29+
) {
30+
}
31+
2632
public function getRuleDefinition(): RuleDefinition
2733
{
2834
return new RuleDefinition('Upgrade ParserFactory create() method', [
@@ -71,14 +77,14 @@ public function refactor(Node $node): ?Node
7177
$args = $node->getArgs();
7278

7379
$value = $this->valueResolver->getValue($args[0]->value);
74-
if ($value === 1) {
80+
if ($value === 1 || $value === 'PhpParser\ParserFactory::PREFER_PHP7') {
7581
$node->name = new Identifier('createForNewestSupportedVersion');
7682
$node->args = [];
7783

7884
return $node;
7985
}
8086

81-
if ($value === 4) {
87+
if ($value === 4 || $value === 'PhpParser\ParserFactory::ONLY_PHP5') {
8288
$node->name = new Identifier('createForVersion');
8389
$fullyQualified = new FullyQualified('PhpParser\PhpVersion');
8490

0 commit comments

Comments
 (0)