diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 7360491..6401bb1 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -21,7 +21,7 @@ jobs: - uses: shivammathur/setup-php@v2 with: - php-version: 8.1 + php-version: 8.2 coverage: none - uses: "ramsey/composer-install@v1" diff --git a/composer.json b/composer.json index 97d56ab..dbebe3a 100644 --- a/composer.json +++ b/composer.json @@ -4,23 +4,16 @@ "license": "MIT", "description": "Rector upgrades rules for PHP-Parser", "require": { - "php": ">=8.1" + "php": ">=8.2" }, "require-dev": { "phpstan/extension-installer": "^1.1", "phpunit/phpunit": "^10.0", - "rector/phpstan-rules": "^0.6", - "phpstan/phpstan": "^1.8.2", - "symplify/phpstan-rules": "^11.1", - "symplify/phpstan-extensions": "^11.1", + "phpstan/phpstan": "^2.0", "symplify/easy-coding-standard": "^11.1", - "symplify/rule-doc-generator": "^11.1", "rector/rector-src": "dev-main", - "phpstan/phpstan-strict-rules": "^1.3", - "phpstan/phpstan-webmozart-assert": "^1.2", + "phpstan/phpstan-webmozart-assert": "^2.0", "symplify/vendor-patches": "^11.1", - "rector/rector-debugging": "dev-main", - "rector/rector-generator": "^0.6.13", "symplify/easy-ci": "11.2.0.72" }, "autoload": { @@ -34,13 +27,9 @@ } }, "scripts": { - "phpstan": "vendor/bin/phpstan analyse --ansi --error-format symplify", + "phpstan": "vendor/bin/phpstan analyse --ansi", "check-cs": "vendor/bin/ecs check --ansi", - "fix-cs": "vendor/bin/ecs check --fix --ansi", - "docs": [ - "vendor/bin/rule-doc-generator generate src --output-file docs/rector_rules_overview.md --ansi", - "vendor/bin/ecs check-markdown docs/rector_rules_overview.md --ansi --fix" - ] + "fix-cs": "vendor/bin/ecs check --fix --ansi" }, "extra": { "enable-patching": true, diff --git a/config/config.php b/config/config.php index c448b91..74a42ef 100644 --- a/config/config.php +++ b/config/config.php @@ -5,13 +5,4 @@ use Rector\Config\RectorConfig; return static function (RectorConfig $rectorConfig): void { - $services = $rectorConfig->services(); - - $services->defaults() - ->public() - ->autowire() - ->autoconfigure(); - - $services->load('Rector\\PhpParser\\', __DIR__ . '/../src') - ->exclude([__DIR__ . '/../src/Set', __DIR__ . '/../src/Rector', __DIR__ . '/../src/ValueObject']); }; diff --git a/easy-ci.php b/easy-ci.php index f52ead2..d5850c4 100644 --- a/easy-ci.php +++ b/easy-ci.php @@ -2,7 +2,7 @@ declare(strict_types=1); -use Rector\Core\Contract\Rector\RectorInterface; +use Rector\Contract\Rector\RectorInterface; use Symplify\EasyCI\Config\EasyCIConfig; return static function (EasyCIConfig $easyCIConfig): void { diff --git a/phpstan.neon b/phpstan.neon index 62e9e02..d82b369 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,5 @@ -includes: - - vendor/symplify/phpstan-rules/config/symplify-rules.neon +#includes: +# - vendor/symplify/phpstan-rules/config/symplify-rules.neon parameters: level: max @@ -14,8 +14,3 @@ parameters: - *Source/* ignoreErrors: - - '#Parameter (.*?) of method (.*?)\:\:refactor\(\) should be contravariant with parameter \$node \(PhpParser\\Node\) of method Rector\\Core\\Contract\\Rector\\PhpRectorInterface\:\:refactor\(\)#' - - - - message: '#Attribute must have all names explicitly defined#' - path: 'tests/*' diff --git a/src/Rector/MethodCall/ParserFactoryRector.php b/src/Rector/MethodCall/ParserFactoryRector.php index 0505156..395c5fe 100644 --- a/src/Rector/MethodCall/ParserFactoryRector.php +++ b/src/Rector/MethodCall/ParserFactoryRector.php @@ -12,7 +12,8 @@ use PhpParser\Node\Name\FullyQualified; use PhpParser\Node\Scalar\String_; use PHPStan\Type\ObjectType; -use Rector\Core\Rector\AbstractRector; +use Rector\PhpParser\Node\Value\ValueResolver; +use Rector\Rector\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -23,6 +24,11 @@ */ final class ParserFactoryRector extends AbstractRector { + public function __construct( + private readonly ValueResolver $valueResolver + ) { + } + public function getRuleDefinition(): RuleDefinition { return new RuleDefinition('Upgrade ParserFactory create() method', [ @@ -71,14 +77,14 @@ public function refactor(Node $node): ?Node $args = $node->getArgs(); $value = $this->valueResolver->getValue($args[0]->value); - if ($value === 1) { + if ($value === 1 || $value === 'PhpParser\ParserFactory::PREFER_PHP7') { $node->name = new Identifier('createForNewestSupportedVersion'); $node->args = []; return $node; } - if ($value === 4) { + if ($value === 4 || $value === 'PhpParser\ParserFactory::ONLY_PHP5') { $node->name = new Identifier('createForVersion'); $fullyQualified = new FullyQualified('PhpParser\PhpVersion');