Skip to content

Commit

Permalink
Prepare to Rector next 2.0 with PHPStan 2 and PHPParser 5
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik committed Nov 21, 2024
1 parent 443901a commit 0ed6e86
Show file tree
Hide file tree
Showing 44 changed files with 74 additions and 72 deletions.
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",
"phpstan/phpstan": "^2.0",
"rector/rector": "dev-main as 1.2.10",
"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",
"phpstan/phpstan-phpunit": "^2.0",
"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
4 changes: 0 additions & 4 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ parameters:
# static reflection
- stubs

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

bootstrapFiles:
- tests/bootstrap-phpstan.php

Expand Down
2 changes: 1 addition & 1 deletion 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
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\Name\FullyQualified;
use PhpParser\Node\Param;
Expand Down Expand Up @@ -124,7 +125,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 @@ -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,6 +5,7 @@
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;
Expand Down Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
namespace Ssch\TYPO3Rector\TYPO311\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\Scalar\String_;
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 @@ -5,9 +5,9 @@
namespace Ssch\TYPO3Rector\TYPO311\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\Scalar\String_;
use Ssch\TYPO3Rector\Rector\AbstractTcaRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
Expand Down
2 changes: 1 addition & 1 deletion rules/TYPO311/v4/MigrateFileFolderConfigurationRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace Ssch\TYPO3Rector\TYPO311\v4;

use PhpParser\Node\ArrayItem;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\ArrayItem;
use PhpParser\Node\Scalar\String_;
use Ssch\TYPO3Rector\Rector\AbstractTcaRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
Expand Down
2 changes: 1 addition & 1 deletion rules/TYPO311/v4/MigrateRootUidToStartingPointsRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace Ssch\TYPO3Rector\TYPO311\v4;

use PhpParser\Node\ArrayItem;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\ArrayItem;
use PhpParser\Node\Scalar\String_;
use Ssch\TYPO3Rector\Rector\AbstractTcaRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
Expand Down
6 changes: 3 additions & 3 deletions rules/TYPO311/v5/SimplifyCheckboxItemsTCARector.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

namespace Ssch\TYPO3Rector\TYPO311\v5;

use PhpParser\Node\ArrayItem;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\ArrayItem;
use PhpParser\Node\Scalar\LNumber;
use PhpParser\Node\Scalar\Int_;
use Ssch\TYPO3Rector\Rector\AbstractTcaRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
Expand Down Expand Up @@ -136,7 +136,7 @@ protected function refactorColumn(Expr $columnName, Expr $columnTca): void
foreach ($firstItemsArray->items as $i => $arrayItem) {
if ($arrayItem instanceof ArrayItem) {
// add a numbered key
$arrayItem->key = new LNumber($i);
$arrayItem->key = new Int_($i);
$this->hasAstBeenChanged = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@

namespace Ssch\TYPO3Rector\TYPO311\v5;

use PhpParser\Modifiers;
use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\PropertyFetch;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Name\FullyQualified;
use PhpParser\Node\PropertyItem;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Expression;
use PhpParser\Node\Stmt\Property;
use PhpParser\Node\Stmt\PropertyProperty;
use PhpParser\Node\Stmt\Return_;
use PHPStan\Type\ObjectType;
use Rector\NodeManipulator\ClassDependencyManipulator;
Expand Down Expand Up @@ -185,7 +186,7 @@ private function addModuleTemplateFactoryToConstructor(Class_ $class): void
new PropertyMetadata(
self::MODULE_TEMPLATE_FACTORY,
new ObjectType('TYPO3\CMS\Backend\Template\ModuleTemplateFactory'),
Class_::MODIFIER_PRIVATE
Modifiers::PRIVATE
)
);
}
Expand All @@ -195,7 +196,7 @@ private function removePropertyFromClass(Class_ $class, string $propertyName): v
foreach ($class->stmts as $stmtKey => $stmt) {
if ($stmt instanceof Property) {
foreach ($stmt->props as $prop) {
if ($prop instanceof PropertyProperty && $propertyName === $prop->name->toString()) {
if ($prop instanceof PropertyItem && $propertyName === $prop->name->toString()) {
unset($class->stmts[$stmtKey]);
}
}
Expand Down Expand Up @@ -326,7 +327,7 @@ private function callModuleTemplateFactoryCreateIfNeeded(ClassMethod $classMetho
}

$existingModuleTemplateFactoryCreateMethodCall = $this->betterNodeFinder->find(
(array) $classMethod->stmts,
$classMethod->stmts,
function (Node $node) {
if (! $node instanceof MethodCall) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Ssch\TYPO3Rector\TYPO311\v5;

use PhpParser\Modifiers;
use PhpParser\Node;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\PropertyFetch;
Expand Down Expand Up @@ -171,7 +172,7 @@ private function addIconFactoryToConstructor(Class_ $class): void
$propertyMetadata = new PropertyMetadata(
'iconFactory',
new ObjectType('TYPO3\CMS\Core\Imaging\IconFactory'),
Class_::MODIFIER_PRIVATE
Modifiers::PRIVATE
);
$this->classDependencyManipulator->addConstructorDependency($class, $propertyMetadata);
}
Expand All @@ -181,7 +182,7 @@ private function addPageRendererToConstructor(Class_ $class): void
$propertyMetadata = new PropertyMetadata(
'pageRenderer',
new ObjectType('TYPO3\CMS\Core\Page\PageRenderer'),
Class_::MODIFIER_PRIVATE
Modifiers::PRIVATE
);

$this->classDependencyManipulator->addConstructorDependency($class, $propertyMetadata);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
namespace Ssch\TYPO3Rector\TYPO312\AnnotationToAttribute;

use PhpParser\Node\Arg;
use PhpParser\Node\ArrayItem;
use PhpParser\Node\Attribute;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\ArrayItem;
use PhpParser\Node\Scalar\String_;
use Ssch\TYPO3Rector\TYPO312\Contract\AttributeDecoratorInterface;

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

use PhpParser\Node\Arg;
use PhpParser\Node\ArrayItem;
use PhpParser\Node\Attribute;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\ArrayItem;
use PhpParser\Node\Identifier;
use PhpParser\Node\Scalar\String_;
use Ssch\TYPO3Rector\TYPO312\Contract\AttributeDecoratorInterface;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
namespace Ssch\TYPO3Rector\TYPO312\AnnotationToAttribute;

use PhpParser\Node\Arg;
use PhpParser\Node\ArrayItem;
use PhpParser\Node\Attribute;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\ArrayItem;
use PhpParser\Node\Expr\ClassConstFetch;
use PhpParser\Node\Identifier;
use PhpParser\Node\Scalar\String_;
Expand Down
4 changes: 2 additions & 2 deletions rules/TYPO312/v0/ChangeExtbaseValidatorsRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ private function manipulateIsValidMethod(Class_ $node): void
return;
}

if ($isValidClassMethod->returnType !== null) {
if ($isValidClassMethod->returnType instanceof Node) {
return;
}

Expand All @@ -249,7 +249,7 @@ private function manipulateValidateMethod(Class_ $node): void
return;
}

if ($validateClassMethod->returnType !== null) {
if ($validateClassMethod->returnType instanceof Node) {
return;
}

Expand Down
Loading

0 comments on commit 0ed6e86

Please sign in to comment.