Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to Rector 2.0 with PHPStan 2 and PHPParser 5 #4450

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
"league/flysystem": "^2.0 || ^3.0",
"league/flysystem-memory": "^2.0 || ^3.0",
"nette/utils": "^3.2.10 || ^4.0.4",
"nikic/php-parser": "^4.18.0",
"phpstan/phpstan": "^1.10.56",
"rector/rector": "^1.1.0",
"nikic/php-parser": "^5.3.1",
"phpstan/phpstan": "^2.0.3",
"rector/rector": "^2.0.0",
"symfony/console": "^5.4 || ^6.4 || ^7.0",
"symfony/filesystem": "^5.4 || ^6.4 || ^7.0",
"symfony/finder": "^5.4 || ^6.4 || ^7.0",
Expand All @@ -53,8 +53,8 @@
"ergebnis/composer-normalize": "^2.42.0",
"php-parallel-lint/php-parallel-lint": "^1.3.2",
"phpstan/extension-installer": "^1.3.1",
"phpstan/phpstan-deprecation-rules": "^1.1.4",
"phpstan/phpstan-phpunit": "^1.3.16",
"phpstan/phpstan-deprecation-rules": "^2.0.1",
"phpstan/phpstan-phpunit": "^2.0.1",
"phpunit/phpunit": "^9.6.17 || ^10.0",
"symfony/config": "^5.0 || ^6.0 || ^7.0",
"symfony/dependency-injection": "^5.4.36 || ^6.4.2 || ^7.0.2",
Expand Down
26 changes: 22 additions & 4 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ parameters:
editorUrl: 'phpstorm://open?file=%%file%%&line=%%line%%'
level: 8

treatPhpDocTypesAsCertain: false

paths:
- bin
- config
Expand All @@ -29,10 +31,6 @@ parameters:
# static reflection
- stubs

# see https://github.com/rectorphp/rector/issues/3490#issue-634342324
featureToggles:
disableRuntimeReflectionProvider: true

bootstrapFiles:
- tests/bootstrap-phpstan.php

Expand All @@ -50,3 +48,23 @@ parameters:

- '#^Call to method needs\(\) on an unknown class Illuminate\\Contracts\\Container\\ContextualBindingBuilder.$#'
- '#^Parameter \#1 \$node \(PhpParser\\Node\\Stmt\\Return_\) of method Ssch\\TYPO3Rector\\TYPO310\\v3\\RemoveExcludeOnTransOrigPointerFieldRector::refactor\(\)#'

-
identifier: phpunit.dataProviderMethod

-
identifier: return.type

-
identifier: method.childReturnType

-
identifier: return.unusedType

-
identifier: assign.propertyType

-
identifier: argument.type

- '#Method .*::provideMinPhpVersion\(\) never returns#'
12 changes: 4 additions & 8 deletions rules/CodeQuality/General/AddErrorCodeToExceptionRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@

use PhpParser\Node;
use PhpParser\Node\Expr\New_;
use PhpParser\Node\Expr\Throw_ as ThrowExpression;
use PhpParser\Node\Stmt\Throw_ as ThrowStatement;
use PhpParser\Node\Expr\Throw_;
use Rector\Rector\AbstractRector;
use Rector\Testing\PHPUnit\StaticPHPUnitEnvironment;
use Ssch\TYPO3Rector\Contract\NoChangelogRequiredInterface;
Expand Down Expand Up @@ -37,11 +36,11 @@ public function getRuleDefinition(): RuleDefinition
*/
public function getNodeTypes(): array
{
return [ThrowStatement::class, ThrowExpression::class];
return [Throw_::class];
}

/**
* @param ThrowStatement|ThrowExpression $node
* @param Throw_ $node
*/
public function refactor(Node $node): ?Node
{
Expand All @@ -63,10 +62,7 @@ public function refactor(Node $node): ?Node
return $node;
}

/**
* @param ThrowStatement|ThrowExpression $node
*/
private function shouldSkip($node): bool
private function shouldSkip(Throw_ $node): bool
{
if (! $node->expr instanceof New_) {
return true;
Expand Down
8 changes: 4 additions & 4 deletions rules/CodeQuality/General/ExtEmConfRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
namespace Ssch\TYPO3Rector\CodeQuality\General;

use PhpParser\Node;
use PhpParser\Node\ArrayItem;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\ArrayDimFetch;
use PhpParser\Node\Expr\ArrayItem;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Scalar\String_;
use Rector\Contract\Rector\ConfigurableRectorInterface;
Expand Down Expand Up @@ -111,7 +111,7 @@ public function refactor(Node $node): ?Node
return null;
}

if ($node->expr->items === [] || $node->expr->items === null) {
if ($node->expr->items === []) {
return null;
}

Expand Down Expand Up @@ -142,7 +142,7 @@ public function refactor(Node $node): ?Node
continue;
}

if ($item->value->items === null) {
if ($item->value->items === []) {
continue;
}

Expand All @@ -160,7 +160,7 @@ public function refactor(Node $node): ?Node
continue;
}

if ($constraintItem->value->items === null) {
if ($constraintItem->value->items === []) {
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Ssch\TYPO3Rector\CodeQuality\General;

use PhpParser\Modifiers;
use PhpParser\Node;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\PropertyFetch;
Expand Down Expand Up @@ -142,7 +143,7 @@ public function refactor(Node $node): ?Node

$this->classDependencyManipulator->addConstructorDependency(
$node,
new PropertyMetadata($paramName, new ObjectType((string) $param->type), Class_::MODIFIER_PROTECTED)
new PropertyMetadata($paramName, new ObjectType((string) $param->type), Modifiers::PROTECTED)
);
$this->removeNodeFromStatements($node, $injectMethod);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Scalar\String_;
use PhpParser\Node\Stmt\Expression;
use PhpParser\NodeTraverser;
use PhpParser\NodeVisitor;
use PHPStan\Type\ObjectType;
use Rector\PhpParser\Printer\BetterStandardPrinter;
use Rector\Rector\AbstractRector;
Expand Down Expand Up @@ -126,7 +126,7 @@ public function refactor(Node $node)
);
}

return NodeTraverser::REMOVE_NODE;
return NodeVisitor::REMOVE_NODE;
}

private function shouldSkip(StaticCall $staticMethodCall): bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Scalar\String_;
use PhpParser\Node\Stmt\Expression;
use PhpParser\NodeTraverser;
use PhpParser\NodeVisitor;
use PHPStan\Type\ObjectType;
use Rector\PhpParser\Node\Value\ValueResolver;
use Rector\PhpParser\Printer\BetterStandardPrinter;
Expand Down Expand Up @@ -131,7 +131,7 @@ public function refactor(Node $node)
);
}

return NodeTraverser::REMOVE_NODE;
return NodeVisitor::REMOVE_NODE;
}

private function shouldSkip(StaticCall $staticMethodCall): bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Scalar\String_;
use PhpParser\Node\Stmt\Expression;
use PhpParser\NodeTraverser;
use PhpParser\NodeVisitor;
use PHPStan\Type\ObjectType;
use Rector\PhpParser\Printer\BetterStandardPrinter;
use Rector\Rector\AbstractRector;
Expand Down Expand Up @@ -126,7 +126,7 @@ public function refactor(Node $node)
);
}

return NodeTraverser::REMOVE_NODE;
return NodeVisitor::REMOVE_NODE;
}

private function shouldSkip(StaticCall $staticMethodCall): bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
namespace Ssch\TYPO3Rector\TYPO310\v0;

use PhpParser\Node;
use PhpParser\Node\ArrayItem;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\ArrayDimFetch;
use PhpParser\Node\Expr\ArrayItem;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\BinaryOp\Identical;
use PhpParser\Node\Expr\ClassConstFetch;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
namespace Ssch\TYPO3Rector\TYPO310\v0;

use PhpParser\Node;
use PhpParser\Node\ArrayItem;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\ArrayItem;
use PhpParser\Node\Expr\BinaryOp\Concat;
use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Expr\Variable;
Expand Down
8 changes: 4 additions & 4 deletions rules/TYPO310/v1/SendNotifyEmailToMailApiRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Name;
use PhpParser\Node\Name\FullyQualified;
use PhpParser\Node\Scalar\LNumber;
use PhpParser\Node\Scalar\Int_;
use PhpParser\Node\Scalar\String_;
use PhpParser\Node\Stmt\Expression;
use PhpParser\Node\Stmt\If_;
Expand Down Expand Up @@ -270,21 +270,21 @@ private function messageParts(): Expression
{
return new Expression(new Assign(new Variable(self::MESSAGE_PARTS), $this->nodeFactory->createFuncCall(
'explode',
[new ConstFetch(new Name('LF')), new Variable(self::MESSAGE), new LNumber(2)]
[new ConstFetch(new Name('LF')), new Variable(self::MESSAGE), new Int_(2)]
)));
}

private function subjectFromMessageParts(): Expression
{
return new Expression(new Assign(new Variable(self::SUBJECT), $this->nodeFactory->createFuncCall(self::TRIM, [
new ArrayDimFetch(new Variable(self::MESSAGE_PARTS), new LNumber(0)),
new ArrayDimFetch(new Variable(self::MESSAGE_PARTS), new Int_(0)),
])));
}

private function bodyFromMessageParts(): Expression
{
return new Expression(new Assign(new Variable('plainMessage'), $this->nodeFactory->createFuncCall(self::TRIM, [
new ArrayDimFetch(new Variable(self::MESSAGE_PARTS), new LNumber(1)),
new ArrayDimFetch(new Variable(self::MESSAGE_PARTS), new Int_(1)),
])));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
namespace Ssch\TYPO3Rector\TYPO310\v3;

use PhpParser\Node;
use PhpParser\Node\ArrayItem;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\ArrayItem;
use PhpParser\Node\Stmt\Return_;
use Ssch\TYPO3Rector\Rector\AbstractTcaRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use PhpParser\Node;
use PhpParser\Node\Expr\BinaryOp\Mul;
use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Scalar\LNumber;
use PhpParser\Node\Scalar\Int_;
use PHPStan\Type\ObjectType;
use Rector\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
Expand Down Expand Up @@ -70,7 +70,7 @@ public function refactor(Node $node): ?Node
new Mul($this->nodeFactory->createFuncCall(
'microtime',
[$this->nodeFactory->createArg($this->nodeFactory->createTrue())]
), new LNumber(1000)),
), new Int_(1000)),
]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@
namespace Ssch\TYPO3Rector\TYPO311\v0;

use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Closure;
use PhpParser\Node\Expr\Exit_;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\Throw_;
use PhpParser\Node\Name\FullyQualified;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Expression;
use PhpParser\Node\Stmt\Function_;
use PhpParser\Node\Stmt\Return_;
use PhpParser\Node\Stmt\Throw_;
use PhpParser\NodeTraverser;
use PhpParser\NodeVisitor;
use PHPStan\Type\ObjectType;
use Rector\Contract\Rector\ConfigurableRectorInterface;
use Rector\Rector\AbstractRector;
Expand Down Expand Up @@ -66,7 +67,7 @@ public function refactor(Node $node): ?Node

$this->traverseNodesWithCallable($node, function (Node $node) {
if ($node instanceof Class_ || $node instanceof Function_ || $node instanceof Closure) {
return NodeTraverser::DONT_TRAVERSE_CURRENT_AND_CHILDREN;
return NodeVisitor::DONT_TRAVERSE_CURRENT_AND_CHILDREN;
}

if (! $node instanceof Return_) {
Expand All @@ -75,13 +76,13 @@ public function refactor(Node $node): ?Node

$responseObjectType = new ObjectType('Psr\\Http\\Message\\ResponseInterface');

if ($node->expr !== null && $this->isObjectType($node->expr, $responseObjectType)) {
if ($node->expr instanceof Expr && $this->isObjectType($node->expr, $responseObjectType)) {
return null;
}

$returnCallExpression = $node->expr;

if ($returnCallExpression !== null && $this->isObjectType(
if ($returnCallExpression instanceof Expr && $this->isObjectType(
$returnCallExpression,
new ObjectType('Psr\Http\Message\ResponseInterface')
)) {
Expand Down Expand Up @@ -174,7 +175,7 @@ public function configure(array $configuration): void

private function shouldSkip(ClassMethod $classMethod): bool
{
if ($classMethod->returnType !== null && $this->isObjectType(
if ($classMethod->returnType instanceof Node && $this->isObjectType(
$classMethod->returnType,
new ObjectType('Psr\\Http\\Message\\ResponseInterface')
)) {
Expand Down Expand Up @@ -243,7 +244,7 @@ private function lastStatementIsExitCall(Node $lastStatement): bool

private function hasExceptionCall(Node $lastStatement): bool
{
if (! $lastStatement instanceof Throw_) {
if (! ($lastStatement instanceof Expression && $lastStatement->expr instanceof Throw_)) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public function createForwardResponseNode(MethodCall $forwardMethodCall)

private function changeActionMethodReturnTypeIfPossible(ClassMethod $actionMethodNode): void
{
if ($actionMethodNode->returnType instanceof Identifier && $actionMethodNode->returnType->name !== null && $actionMethodNode->returnType->name === 'void') {
if ($actionMethodNode->returnType instanceof Identifier && $actionMethodNode->returnType->name === 'void') {
$actionMethodNode->returnType = null;
}

Expand All @@ -188,7 +188,7 @@ private function changeActionMethodReturnTypeIfPossible(ClassMethod $actionMetho
$actionMethodNode->setAttribute(AttributeKey::COMMENTS, $comments);

// Add returnType only if it is the only statement, otherwise it is not reliable
if (is_countable($actionMethodNode->stmts) && count((array) $actionMethodNode->stmts) === 1) {
if (is_countable($actionMethodNode->stmts) && count($actionMethodNode->stmts) === 1) {
$actionMethodNode->returnType = new FullyQualified('Psr\Http\Message\ResponseInterface');
}
}
Expand Down
2 changes: 1 addition & 1 deletion rules/TYPO311/v2/MigrateFrameModuleToSvgTreeRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
namespace Ssch\TYPO3Rector\TYPO311\v2;

use PhpParser\Node;
use PhpParser\Node\ArrayItem;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\ArrayItem;
use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Scalar\String_;
use PHPStan\Type\ObjectType;
Expand Down
Loading
Loading