Skip to content

Commit

Permalink
Bump to PHPStan 2 and PHPParser 5
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik committed Nov 20, 2024
1 parent 9639ef9 commit 4413acd
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 34 deletions.
19 changes: 4 additions & 15 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,11 @@
"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": {
Expand All @@ -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,
Expand Down
9 changes: 0 additions & 9 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
};
9 changes: 2 additions & 7 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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/*'
12 changes: 9 additions & 3 deletions src/Rector/MethodCall/ParserFactoryRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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', [
Expand Down Expand Up @@ -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');

Expand Down

0 comments on commit 4413acd

Please sign in to comment.