diff --git a/composer.json b/composer.json index 618bba1afb7..2b75955037e 100644 --- a/composer.json +++ b/composer.json @@ -56,7 +56,7 @@ "symplify/phpstan-rules": "^14.12.3", "tomasvotruba/class-leak": "^2.1", "tomasvotruba/fast-unit": "^0.1", - "tomasvotruba/type-coverage": "^2.3", + "tomasvotruba/type-coverage": "^2.3.6", "tomasvotruba/unused-public": "^2.2", "tracy/tracy": "^2.12" }, diff --git a/phpstan.neon b/phpstan.neon index ea6830a4c95..975d5b858cc 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -10,7 +10,7 @@ rules: parameters: level: 8 - # reportUnmatchedIgnoredErrors: false + reportUnmatchedIgnoredErrors: false errorFormat: symplify # see https://phpstan.org/writing-php-code/phpdoc-types#global-type-aliases @@ -281,10 +281,6 @@ parameters: - src/NodeTypeResolver/PHPStan/Type/TypeFactory.php - rules/Arguments/ArgumentDefaultValueReplacer.php - - - identifier: return.type - message: '#should return non\-empty\-string but returns string#' - # from mapper interface - identifier: return.unusedType @@ -296,16 +292,6 @@ parameters: message: '#Method (.*?)refactor\(\) (never returns|should return) (.*?)#' path: rules/Php70/Rector/If_/IfToSpaceshipRector.php - - - identifier: symplify.forbiddenFuncCall - message: '#Function "var_dump\(\)" cannot be used/left in the code#' - path: src/functions/node_helper.php - - - - identifier: symplify.forbiddenFuncCall - message: '#Function "class_exists\(\)" cannot be used/left in the code#' - path: src/Configuration/OnlyRuleResolver.php - - identifier: symplify.forbiddenFuncCall message: '#Function "property_exists\(\)" cannot be used/left in the code#' @@ -323,35 +309,22 @@ parameters: - src/Validation/RectorConfigValidator.php - src/Testing/PHPUnit/AbstractLazyTestCase.php - src/Reporting/DeprecatedRulesReporter.php + - src/Configuration/OnlyRuleResolver.php - # required for reflection - - - identifier: symplify.forbiddenFuncCall - message: '#Function "(.*?)\(\)" cannot be used/left in the code#' - path: src/Util/Reflection/PrivatesAccessor.php - - - - identifier: symplify.forbiddenFuncCall - message: '#Function "(function_exists|dump_node)\(\)" cannot be used/left in the code#' - path: src/functions/node_helper.php - - # chicken/egg - - - identifier: symplify.forbiddenFuncCall - message: '#Function "(d|dd)\(\)" cannot be used/left in the code#' - path: tests/debug_functions.php - - # debug functions + # debug and internal functions - identifier: symplify.forbiddenFuncCall - message: '#Function "function_exists\(\)" cannot be used/left in the code\: use ReflectionProvider\->has\*\(\) instead#' - path: tests/debug_functions.php + paths: + - src/functions/node_helper.php + - tests/debug_functions.php + - src/Util/Reflection/PrivatesAccessor.php # checks for rector always autoloaded rules only - identifier: symplify.forbiddenFuncCall message: '#Function "(class_exists|interface_exists)\(\)" cannot be used/left in the code\: use ReflectionProvider\->has\*\(\) instead#' - path: src/Skipper/SkipCriteriaResolver/SkippedClassResolver.php + paths: + - src/Skipper/SkipCriteriaResolver/SkippedClassResolver.php # native filesystem calls, required for performance reasons - @@ -408,36 +381,9 @@ parameters: # fixture Rector rules - identifier: symplify.seeAnnotationToTest - path: tests/Issues/ - - # dev rule - - - identifier: symplify.seeAnnotationToTest - message: '#Class "Rector\\Utils\\Rector\\MoveAbstractRectorToChildrenRector" is missing @see annotation with test case class reference#' - - - - identifier: symplify.seeAnnotationToTest - path: tests/PhpParser/NodeTraverser/StopTraverseOnTypeChange/Class_ - - # wider types for external use - - - identifier: typePerfect.narrowPublicClassMethodParamType - message: '#Parameters should have "PhpParser\\Node\\Stmt\\ClassMethod" types as the only types passed to this method#' - path: src/Reflection/ClassModifierChecker.php - - # false positive - should be fixed - - - identifier: typePerfect.narrowPublicClassMethodParamType - message: '#Parameters should have "PhpParser\\Node\\Expr\\Closure" types as the only types passed to this method#' - - - - identifier: typePerfect.narrowPublicClassMethodParamType - message: '#Parameters should have "PhpParser\\Node\\Stmt\\ClassMethod" types as the only types passed to this method#' - path: src/VendorLocker/ParentClassMethodTypeOverrideGuard.php - - - - identifier: typePerfect.narrowReturnObjectType - message: '#Provide more specific return type "Iterator|PhpParser\\Node" over abstract one#' + paths: + - tests/Issues/ + - tests/PhpParser/NodeTraverser/StopTraverseOnTypeChange/Class_ - identifier: typePerfect.noMixedMethodCaller diff --git a/rules/TypeDeclaration/Rector/ClassMethod/AddVoidReturnTypeWhereNoReturnRector.php b/rules/TypeDeclaration/Rector/ClassMethod/AddVoidReturnTypeWhereNoReturnRector.php index 88fc60ba5fb..5feb4c54fe8 100644 --- a/rules/TypeDeclaration/Rector/ClassMethod/AddVoidReturnTypeWhereNoReturnRector.php +++ b/rules/TypeDeclaration/Rector/ClassMethod/AddVoidReturnTypeWhereNoReturnRector.php @@ -9,6 +9,7 @@ use PhpParser\Node\Identifier; use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\Expression; +use Rector\PHPStan\ScopeFetcher; use Rector\Rector\AbstractRector; use Rector\Reflection\ClassModifierChecker; use Rector\TypeDeclaration\TypeInferer\SilentVoidResolver; @@ -119,7 +120,13 @@ private function shouldSkipClassMethod(ClassMethod $classMethod): bool return ! $this->classModifierChecker->isInsideFinalClass($classMethod); } - return $this->classModifierChecker->isInsideAbstractClass($classMethod) && $classMethod->getStmts() === []; + $scope = ScopeFetcher::fetch($classMethod); + if (! $scope->isInClass()) { + return false; + } + + $classReflection = $scope->getClassReflection(); + return $classReflection->isAbstract(); } private function isNotFinalAndHasExceptionOnly(ClassMethod $classMethod): bool diff --git a/src/BetterPhpDocParser/PhpDoc/SpacelessPhpDocTagNode.php b/src/BetterPhpDocParser/PhpDoc/SpacelessPhpDocTagNode.php index d7928efd494..70647241499 100644 --- a/src/BetterPhpDocParser/PhpDoc/SpacelessPhpDocTagNode.php +++ b/src/BetterPhpDocParser/PhpDoc/SpacelessPhpDocTagNode.php @@ -4,7 +4,6 @@ namespace Rector\BetterPhpDocParser\PhpDoc; -use Override; use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode; use Stringable; @@ -14,7 +13,6 @@ */ final class SpacelessPhpDocTagNode extends PhpDocTagNode implements Stringable { - #[Override] public function __toString(): string { return $this->name . $this->value; diff --git a/src/BetterPhpDocParser/PhpDocParser/BetterPhpDocParser.php b/src/BetterPhpDocParser/PhpDocParser/BetterPhpDocParser.php index fc08c491ecc..e9111c1c46a 100644 --- a/src/BetterPhpDocParser/PhpDocParser/BetterPhpDocParser.php +++ b/src/BetterPhpDocParser/PhpDocParser/BetterPhpDocParser.php @@ -5,7 +5,6 @@ namespace Rector\BetterPhpDocParser\PhpDocParser; use Nette\Utils\Strings; -use Override; use PhpParser\Node; use PHPStan\PhpDocParser\Ast\PhpDoc\GenericTagValueNode; use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocChildNode; @@ -111,7 +110,6 @@ public function parseWithNode(BetterTokenIterator $betterTokenIterator, Node $no return $phpDocNode; } - #[Override] public function parseTag(TokenIterator $tokenIterator): PhpDocTagNode { // replace generic nodes with DoctrineAnnotations @@ -128,7 +126,6 @@ public function parseTag(TokenIterator $tokenIterator): PhpDocTagNode /** * @param BetterTokenIterator $tokenIterator */ - #[Override] public function parseTagValue(TokenIterator $tokenIterator, string $tag): PhpDocTagValueNode { $isPrecededByHorizontalWhitespace = $tokenIterator->isPrecededByHorizontalWhitespace(); diff --git a/src/BetterPhpDocParser/PhpDocParser/ClassAnnotationMatcher.php b/src/BetterPhpDocParser/PhpDocParser/ClassAnnotationMatcher.php index 5802b15d199..cbf6919ee9d 100644 --- a/src/BetterPhpDocParser/PhpDocParser/ClassAnnotationMatcher.php +++ b/src/BetterPhpDocParser/PhpDocParser/ClassAnnotationMatcher.php @@ -11,6 +11,7 @@ use PHPStan\Analyser\Scope; use PHPStan\Reflection\ReflectionProvider; use Rector\CodingStyle\NodeAnalyzer\UseImportNameMatcher; +use Rector\Exception\ShouldNotHappenException; use Rector\Naming\Naming\UseImportsResolver; use Rector\NodeTypeResolver\Node\AttributeKey; @@ -20,7 +21,7 @@ final class ClassAnnotationMatcher { /** - * @var array + * @var array */ private array $fullyQualifiedNameByHash = []; @@ -42,6 +43,9 @@ public function resolveTagFullyQualifiedName(string $tag, Node $node): string } $tag = ltrim($tag, '@'); + if ($tag === '') { + throw new ShouldNotHappenException(); + } $uses = $this->useImportsResolver->resolve(); $fullyQualifiedClass = $this->resolveFullyQualifiedClass($uses, $node, $tag); diff --git a/src/BetterPhpDocParser/ValueObject/PhpDoc/SpacingAwareTemplateTagValueNode.php b/src/BetterPhpDocParser/ValueObject/PhpDoc/SpacingAwareTemplateTagValueNode.php index d0fa17733b9..92dd63ae7ac 100644 --- a/src/BetterPhpDocParser/ValueObject/PhpDoc/SpacingAwareTemplateTagValueNode.php +++ b/src/BetterPhpDocParser/ValueObject/PhpDoc/SpacingAwareTemplateTagValueNode.php @@ -4,7 +4,6 @@ namespace Rector\BetterPhpDocParser\ValueObject\PhpDoc; -use Override; use PHPStan\PhpDocParser\Ast\PhpDoc\TemplateTagValueNode; use PHPStan\PhpDocParser\Ast\Type\TypeNode; use Stringable; @@ -20,7 +19,6 @@ public function __construct( parent::__construct($name, $typeNode, $description); } - #[Override] public function __toString(): string { // @see https://github.com/rectorphp/rector/issues/3438 diff --git a/src/BetterPhpDocParser/ValueObject/Type/BracketsAwareIntersectionTypeNode.php b/src/BetterPhpDocParser/ValueObject/Type/BracketsAwareIntersectionTypeNode.php index f0544b25f94..d1a0afae706 100644 --- a/src/BetterPhpDocParser/ValueObject/Type/BracketsAwareIntersectionTypeNode.php +++ b/src/BetterPhpDocParser/ValueObject/Type/BracketsAwareIntersectionTypeNode.php @@ -4,13 +4,11 @@ namespace Rector\BetterPhpDocParser\ValueObject\Type; -use Override; use PHPStan\PhpDocParser\Ast\Type\IntersectionTypeNode; use Stringable; final class BracketsAwareIntersectionTypeNode extends IntersectionTypeNode implements Stringable { - #[Override] public function __toString(): string { return implode('&', $this->types); diff --git a/src/BetterPhpDocParser/ValueObject/Type/BracketsAwareUnionTypeNode.php b/src/BetterPhpDocParser/ValueObject/Type/BracketsAwareUnionTypeNode.php index e4bff800d1a..6d8d8e617ae 100644 --- a/src/BetterPhpDocParser/ValueObject/Type/BracketsAwareUnionTypeNode.php +++ b/src/BetterPhpDocParser/ValueObject/Type/BracketsAwareUnionTypeNode.php @@ -4,7 +4,6 @@ namespace Rector\BetterPhpDocParser\ValueObject\Type; -use Override; use PHPStan\PhpDocParser\Ast\Type\TypeNode; use PHPStan\PhpDocParser\Ast\Type\UnionTypeNode; use Stringable; @@ -24,7 +23,6 @@ public function __construct( /** * Preserve common format */ - #[Override] public function __toString(): string { $types = []; diff --git a/src/BetterPhpDocParser/ValueObject/Type/FullyQualifiedIdentifierTypeNode.php b/src/BetterPhpDocParser/ValueObject/Type/FullyQualifiedIdentifierTypeNode.php index ba15a85d3df..59c050c2099 100644 --- a/src/BetterPhpDocParser/ValueObject/Type/FullyQualifiedIdentifierTypeNode.php +++ b/src/BetterPhpDocParser/ValueObject/Type/FullyQualifiedIdentifierTypeNode.php @@ -4,13 +4,11 @@ namespace Rector\BetterPhpDocParser\ValueObject\Type; -use Override; use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode; use Stringable; final class FullyQualifiedIdentifierTypeNode extends IdentifierTypeNode implements Stringable { - #[Override] public function __toString(): string { return '\\' . ltrim($this->name, '\\'); diff --git a/src/BetterPhpDocParser/ValueObject/Type/SpacingAwareArrayTypeNode.php b/src/BetterPhpDocParser/ValueObject/Type/SpacingAwareArrayTypeNode.php index 1a7da5c9ef2..4e33184ab26 100644 --- a/src/BetterPhpDocParser/ValueObject/Type/SpacingAwareArrayTypeNode.php +++ b/src/BetterPhpDocParser/ValueObject/Type/SpacingAwareArrayTypeNode.php @@ -4,7 +4,6 @@ namespace Rector\BetterPhpDocParser\ValueObject\Type; -use Override; use PHPStan\PhpDocParser\Ast\Type\ArrayTypeNode; use PHPStan\PhpDocParser\Ast\Type\CallableTypeNode; use PHPStan\PhpDocParser\Ast\Type\GenericTypeNode; @@ -15,7 +14,6 @@ final class SpacingAwareArrayTypeNode extends ArrayTypeNode implements Stringable { - #[Override] public function __toString(): string { if ($this->type instanceof CallableTypeNode) { diff --git a/src/BetterPhpDocParser/ValueObject/Type/SpacingAwareCallableTypeNode.php b/src/BetterPhpDocParser/ValueObject/Type/SpacingAwareCallableTypeNode.php index 7eb7ddf16ec..3b7957d6413 100644 --- a/src/BetterPhpDocParser/ValueObject/Type/SpacingAwareCallableTypeNode.php +++ b/src/BetterPhpDocParser/ValueObject/Type/SpacingAwareCallableTypeNode.php @@ -4,13 +4,11 @@ namespace Rector\BetterPhpDocParser\ValueObject\Type; -use Override; use PHPStan\PhpDocParser\Ast\Type\CallableTypeNode; use Stringable; final class SpacingAwareCallableTypeNode extends CallableTypeNode implements Stringable { - #[Override] public function __toString(): string { // keep original (Psalm?) format, see https://github.com/rectorphp/rector/issues/2841 diff --git a/src/Config/RectorConfig.php b/src/Config/RectorConfig.php index b45d6f678e5..0697c6ef53a 100644 --- a/src/Config/RectorConfig.php +++ b/src/Config/RectorConfig.php @@ -13,7 +13,6 @@ use Rector\Configuration\Option; use Rector\Configuration\Parameter\SimpleParameterProvider; use Rector\Configuration\RectorConfigBuilder; -use Rector\Contract\DependencyInjection\RelatedConfigInterface; use Rector\Contract\Rector\ConfigurableRectorInterface; use Rector\Contract\Rector\RectorInterface; use Rector\Enum\Config\Defaults; @@ -294,18 +293,6 @@ public function rule(string $rectorClass): void // for cache invalidation in case of change SimpleParameterProvider::addParameter(Option::REGISTERED_RECTOR_RULES, $rectorClass); } - - if (is_a($rectorClass, RelatedConfigInterface::class, true)) { - $configFile = $rectorClass::getConfigFile(); - - Assert::file($configFile, sprintf( - 'The config path "%s" in "%s::getConfigFile()" could not be found', - $configFile, - $rectorClass - )); - - $this->import($configFile); - } } /** @@ -565,7 +552,6 @@ public function bound(string $abstract): bool * * @param class-string $contract */ - #[Override] public function forgetByContract(string $contract): void { parent::forgetByContract($contract); diff --git a/src/Console/ConsoleApplication.php b/src/Console/ConsoleApplication.php index 498dd412591..80fd68a27c9 100644 --- a/src/Console/ConsoleApplication.php +++ b/src/Console/ConsoleApplication.php @@ -5,7 +5,6 @@ namespace Rector\Console; use Composer\XdebugHandler\XdebugHandler; -use Override; use Rector\Application\VersionResolver; use Rector\ChangesReporting\Output\ConsoleOutputFormatter; use Rector\Configuration\Option; @@ -41,7 +40,6 @@ public function __construct( $this->setDefaultCommand('process'); } - #[Override] public function doRun(InputInterface $input, OutputInterface $output): int { // support "-v" as an alias for "--version", as "verbose" option is removed @@ -102,7 +100,6 @@ public function doRun(InputInterface $input, OutputInterface $output): int return parent::doRun($input, $output); } - #[Override] protected function getDefaultInputDefinition(): InputDefinition { $defaultInputDefinition = parent::getDefaultInputDefinition(); diff --git a/src/Console/Style/RectorStyle.php b/src/Console/Style/RectorStyle.php index e3a4db616b8..0b8b5d7c4dc 100644 --- a/src/Console/Style/RectorStyle.php +++ b/src/Console/Style/RectorStyle.php @@ -5,7 +5,6 @@ namespace Rector\Console\Style; use OndraM\CiDetector\CiDetector; -use Override; use Symfony\Component\Console\Exception\RuntimeException; use Symfony\Component\Console\Helper\ProgressBar; use Symfony\Component\Console\Input\InputInterface; @@ -31,7 +30,6 @@ public function __construct(InputInterface $input, OutputInterface $output) /** * @see https://github.com/phpstan/phpstan-src/commit/0993d180e5a15a17631d525909356081be59ffeb */ - #[Override] public function createProgressBar(int $max = 0): ProgressBar { $progressBar = parent::createProgressBar($max); @@ -58,7 +56,6 @@ public function createProgressBar(int $max = 0): ProgressBar return $progressBar; } - #[Override] public function progressAdvance(int $step = 1): void { // hide progress bar in tests diff --git a/src/Contract/DependencyInjection/RelatedConfigInterface.php b/src/Contract/DependencyInjection/RelatedConfigInterface.php deleted file mode 100644 index c2f17ddcaaa..00000000000 --- a/src/Contract/DependencyInjection/RelatedConfigInterface.php +++ /dev/null @@ -1,13 +0,0 @@ -unwrapFileNode($stmts); @@ -104,7 +102,6 @@ public function print(Node|array|null $node): string /** * @param Node[] $stmts */ - #[Override] public function prettyPrintFile(array $stmts): string { // to keep indexes from 0 @@ -122,7 +119,6 @@ protected function pInterpolatedStringPart(InterpolatedStringPart $interpolatedS return $interpolatedStringPart->value; } - #[Override] protected function p( Node $node, int $precedence = self::MAX_PRECEDENCE, @@ -150,7 +146,6 @@ protected function pStmt_FileNode(FileNode $fileNode): string return $this->pStmts($fileNode->stmts); } - #[Override] protected function pExpr_ArrowFunction(ArrowFunction $arrowFunction, int $precedence, int $lhsPrecedence): string { if (! $arrowFunction->hasAttribute(AttributeKey::COMMENTS)) { @@ -186,7 +181,6 @@ protected function pExpr_ArrowFunction(ArrowFunction $arrowFunction, int $preced /** * This allows to use both spaces and tabs vs. original space-only */ - #[Override] protected function setIndentLevel(int $level): void { $level = max($level, 0); @@ -197,7 +191,6 @@ protected function setIndentLevel(int $level): void /** * This allows to use both spaces and tabs vs. original space-only */ - #[Override] protected function indent(): void { $indentSize = SimpleParameterProvider::provideIntParameter(Option::INDENT_SIZE); @@ -209,7 +202,6 @@ protected function indent(): void /** * This allows to use both spaces and tabs vs. original space-only */ - #[Override] protected function outdent(): void { if ($this->getIndentCharacter() === ' ') { @@ -229,7 +221,6 @@ protected function outdent(): void * @param mixed[] $nodes * @param mixed[] $origNodes */ - #[Override] protected function pArray( array $nodes, array $origNodes, @@ -258,7 +249,6 @@ protected function pArray( * Do not add "()" on Expressions * @see https://github.com/rectorphp/rector/pull/401#discussion_r181487199 */ - #[Override] protected function pExpr_Yield(Yield_ $yield, int $precedence, int $lhsPrecedence): string { if (! $yield->value instanceof Expr) { @@ -280,7 +270,6 @@ protected function pExpr_Yield(Yield_ $yield, int $precedence, int $lhsPrecedenc /** * Print new lined array items when newlined_array_print is set to true */ - #[Override] protected function pExpr_Array(Array_ $array): string { if ($array->getAttribute(AttributeKey::NEWLINED_ARRAY_PRINT) === true) { @@ -293,7 +282,6 @@ protected function pExpr_Array(Array_ $array): string return parent::pExpr_Array($array); } - #[Override] protected function pExpr_BinaryOp_Pipe(Pipe $node, int $precedence, int $lhsPrecedence): string { return $this->pInfixOp( @@ -309,7 +297,6 @@ protected function pExpr_BinaryOp_Pipe(Pipe $node, int $precedence, int $lhsPrec /** * Fixes escaping of regular patterns */ - #[Override] protected function pScalar_String(String_ $string): string { if ($string->getAttribute(AttributeKey::DOC_INDENTATION) === '__REMOVED__') { @@ -337,7 +324,6 @@ protected function pScalar_String(String_ $string): string /** * It remove all spaces extra to parent */ - #[Override] protected function pStmt_Declare(Declare_ $declare): string { $declareString = parent::pStmt_Declare($declare); @@ -345,7 +331,6 @@ protected function pStmt_Declare(Declare_ $declare): string return Strings::replace($declareString, '#\s+#'); } - #[Override] protected function pExpr_Ternary(Ternary $ternary, int $precedence, int $lhsPrecedence): string { $kind = $ternary->getAttribute(AttributeKey::KIND); @@ -360,7 +345,6 @@ protected function pExpr_Ternary(Ternary $ternary, int $precedence, int $lhsPrec /** * Used in rector-downgrade-php */ - #[Override] protected function pScalar_InterpolatedString(InterpolatedString $interpolatedString): string { $content = parent::pScalar_InterpolatedString($interpolatedString); @@ -372,7 +356,6 @@ protected function pScalar_InterpolatedString(InterpolatedString $interpolatedSt return $content; } - #[Override] protected function pExpr_MethodCall(MethodCall $methodCall): string { if (! $methodCall->var instanceof CallLike) { @@ -400,7 +383,6 @@ protected function pExpr_MethodCall(MethodCall $methodCall): string . '(' . $this->pMaybeMultiline($methodCall->args) . ')'; } - #[Override] protected function pInfixOp( string $class, Node $leftNode, @@ -413,7 +395,6 @@ protected function pInfixOp( return parent::pInfixOp($class, $leftNode, $operatorString, $rightNode, $precedence, $lhsPrecedence); } - #[Override] protected function pExpr_Instanceof(Instanceof_ $instanceof, int $precedence, int $lhsPrecedence): string { $this->wrapAssign($instanceof->expr, $instanceof->class); diff --git a/src/PostRector/Rector/ClassRenamingPostRector.php b/src/PostRector/Rector/ClassRenamingPostRector.php index 0ff5e3ce395..2c13b0d85f3 100644 --- a/src/PostRector/Rector/ClassRenamingPostRector.php +++ b/src/PostRector/Rector/ClassRenamingPostRector.php @@ -4,7 +4,6 @@ namespace Rector\PostRector\Rector; -use Override; use PhpParser\Node; use PhpParser\NodeVisitor; use Rector\Configuration\RenamedClassesDataCollector; @@ -49,7 +48,6 @@ public function enterNode(Node $node): FileNode|int return NodeVisitor::STOP_TRAVERSAL; } - #[Override] public function shouldTraverse(array $stmts): bool { $this->oldToNewClasses = $this->renamedClassesDataCollector->getOldToNewClasses(); diff --git a/src/PostRector/Rector/DocblockNameImportingPostRector.php b/src/PostRector/Rector/DocblockNameImportingPostRector.php index 2089d5f0d89..407f8de47db 100644 --- a/src/PostRector/Rector/DocblockNameImportingPostRector.php +++ b/src/PostRector/Rector/DocblockNameImportingPostRector.php @@ -4,7 +4,6 @@ namespace Rector\PostRector\Rector; -use Override; use PhpParser\Node; use PhpParser\Node\Param; use PhpParser\Node\Stmt; @@ -48,7 +47,6 @@ public function enterNode(Node $node): Node|null /** * @param Stmt[] $stmts */ - #[Override] public function shouldTraverse(array $stmts): bool { return $this->addUseStatementGuard->shouldTraverse($stmts, $this->getFile()->getFilePath()); diff --git a/src/PostRector/Rector/NameImportingPostRector.php b/src/PostRector/Rector/NameImportingPostRector.php index 7052b406ba3..7c63e54b217 100644 --- a/src/PostRector/Rector/NameImportingPostRector.php +++ b/src/PostRector/Rector/NameImportingPostRector.php @@ -4,7 +4,6 @@ namespace Rector\PostRector\Rector; -use Override; use PhpParser\Node; use PhpParser\Node\Name; use PhpParser\Node\Name\FullyQualified; @@ -57,7 +56,6 @@ public function enterNode(Node $node): Name|null /** * @param Stmt[] $stmts */ - #[Override] public function shouldTraverse(array $stmts): bool { return $this->addUseStatementGuard->shouldTraverse($stmts, $this->getFile()->getFilePath()); diff --git a/src/PostRector/Rector/UseAddingPostRector.php b/src/PostRector/Rector/UseAddingPostRector.php index ae9821fe1df..bedd35d3ed5 100644 --- a/src/PostRector/Rector/UseAddingPostRector.php +++ b/src/PostRector/Rector/UseAddingPostRector.php @@ -4,7 +4,6 @@ namespace Rector\PostRector\Rector; -use Override; use PhpParser\Node; use PhpParser\Node\Stmt; use PhpParser\NodeVisitor; @@ -22,7 +21,6 @@ public function __construct( /** * @param Stmt[] $stmts */ - #[Override] public function shouldTraverse(array $stmts): bool { $fileNode = $stmts[0] ?? null; diff --git a/src/Reflection/ClassModifierChecker.php b/src/Reflection/ClassModifierChecker.php index 063e03054df..220e50e9c88 100644 --- a/src/Reflection/ClassModifierChecker.php +++ b/src/Reflection/ClassModifierChecker.php @@ -23,14 +23,4 @@ public function isInsideFinalClass(Node $node): bool return $classReflection->isFinalByKeyword(); } - - public function isInsideAbstractClass(Node $node): bool - { - $classReflection = $this->reflectionResolver->resolveClassReflection($node); - if (! $classReflection instanceof ClassReflection) { - return false; - } - - return $classReflection->isAbstract(); - } } diff --git a/src/StaticTypeMapper/ValueObject/Type/AliasedObjectType.php b/src/StaticTypeMapper/ValueObject/Type/AliasedObjectType.php index 2522c8cae13..58e4cc547b8 100644 --- a/src/StaticTypeMapper/ValueObject/Type/AliasedObjectType.php +++ b/src/StaticTypeMapper/ValueObject/Type/AliasedObjectType.php @@ -4,7 +4,6 @@ namespace Rector\StaticTypeMapper\ValueObject\Type; -use Override; use PhpParser\Node\Name; use PhpParser\Node\Stmt\Use_; use PhpParser\Node\UseItem; @@ -54,7 +53,6 @@ public function areShortNamesEqual(self|FullyQualifiedObjectType $comparedObject return $this->getShortName() === $comparedObjectType->getShortName(); } - #[Override] public function equals(Type $type): bool { $className = ClassNameFromObjectTypeResolver::resolve($type); diff --git a/src/StaticTypeMapper/ValueObject/Type/FullyQualifiedObjectType.php b/src/StaticTypeMapper/ValueObject/Type/FullyQualifiedObjectType.php index 4c3aee43bd6..d242e323f9d 100644 --- a/src/StaticTypeMapper/ValueObject/Type/FullyQualifiedObjectType.php +++ b/src/StaticTypeMapper/ValueObject/Type/FullyQualifiedObjectType.php @@ -5,7 +5,6 @@ namespace Rector\StaticTypeMapper\ValueObject\Type; use Nette\Utils\Strings; -use Override; use PhpParser\Node\Name; use PhpParser\Node\Stmt\Use_; use PhpParser\Node\UseItem; @@ -67,7 +66,6 @@ public function getShortNameLowered(): string return strtolower($this->getShortName()); } - #[Override] public function equals(Type $type): bool { $isEqual = parent::equals($type); diff --git a/src/StaticTypeMapper/ValueObject/Type/NonExistingObjectType.php b/src/StaticTypeMapper/ValueObject/Type/NonExistingObjectType.php index be77cd201cd..2be0faf52fe 100644 --- a/src/StaticTypeMapper/ValueObject/Type/NonExistingObjectType.php +++ b/src/StaticTypeMapper/ValueObject/Type/NonExistingObjectType.php @@ -4,13 +4,11 @@ namespace Rector\StaticTypeMapper\ValueObject\Type; -use Override; use PHPStan\Type\ObjectType; use PHPStan\Type\Type; final class NonExistingObjectType extends ObjectType { - #[Override] public function equals(Type $type): bool { $isEqual = parent::equals($type); diff --git a/src/StaticTypeMapper/ValueObject/Type/ShortenedGenericObjectType.php b/src/StaticTypeMapper/ValueObject/Type/ShortenedGenericObjectType.php index b4ebf1d0183..916ba0da943 100644 --- a/src/StaticTypeMapper/ValueObject/Type/ShortenedGenericObjectType.php +++ b/src/StaticTypeMapper/ValueObject/Type/ShortenedGenericObjectType.php @@ -4,7 +4,6 @@ namespace Rector\StaticTypeMapper\ValueObject\Type; -use Override; use PHPStan\Type\Generic\GenericObjectType; use PHPStan\Type\IsSuperTypeOfResult; use PHPStan\Type\Type; @@ -25,7 +24,6 @@ public function __construct( parent::__construct($shortName, $types); } - #[Override] public function isSuperTypeOf(Type $type): IsSuperTypeOfResult { $genericObjectType = new GenericObjectType($this->fullyQualifiedName, $this->getTypes()); diff --git a/src/StaticTypeMapper/ValueObject/Type/ShortenedObjectType.php b/src/StaticTypeMapper/ValueObject/Type/ShortenedObjectType.php index 396d28626e9..a6c0738d2ee 100644 --- a/src/StaticTypeMapper/ValueObject/Type/ShortenedObjectType.php +++ b/src/StaticTypeMapper/ValueObject/Type/ShortenedObjectType.php @@ -4,7 +4,6 @@ namespace Rector\StaticTypeMapper\ValueObject\Type; -use Override; use PHPStan\Type\IsSuperTypeOfResult; use PHPStan\Type\ObjectType; use PHPStan\Type\Type; @@ -24,7 +23,6 @@ public function __construct( parent::__construct($shortName); } - #[Override] public function isSuperTypeOf(Type $type): IsSuperTypeOfResult { $fullyQualifiedObjectType = new ObjectType($this->fullyQualifiedName); @@ -44,7 +42,6 @@ public function getFullyQualifiedName(): string return $this->fullyQualifiedName; } - #[Override] public function equals(Type $type): bool { $isEqual = parent::equals($type); diff --git a/src/StaticTypeMapper/ValueObject/Type/SimpleStaticType.php b/src/StaticTypeMapper/ValueObject/Type/SimpleStaticType.php index d97ba4c2d84..d975c714b86 100644 --- a/src/StaticTypeMapper/ValueObject/Type/SimpleStaticType.php +++ b/src/StaticTypeMapper/ValueObject/Type/SimpleStaticType.php @@ -4,7 +4,6 @@ namespace Rector\StaticTypeMapper\ValueObject\Type; -use Override; use PHPStan\Type\StaticType; final class SimpleStaticType extends StaticType @@ -14,7 +13,6 @@ public function __construct( ) { } - #[Override] public function getClassName(): string { return $this->className; diff --git a/src/VendorLocker/ParentClassMethodTypeOverrideGuard.php b/src/VendorLocker/ParentClassMethodTypeOverrideGuard.php index d1f9943311d..7e269c88868 100644 --- a/src/VendorLocker/ParentClassMethodTypeOverrideGuard.php +++ b/src/VendorLocker/ParentClassMethodTypeOverrideGuard.php @@ -5,7 +5,6 @@ namespace Rector\VendorLocker; use PhpParser\Node; -use PhpParser\Node\Stmt\ClassLike; use PhpParser\Node\Stmt\ClassMethod; use PHPStan\Reflection\ClassReflection; use PHPStan\Reflection\MethodReflection; @@ -39,7 +38,7 @@ public function __construct( * classes, so type-declaration rules must leave it untouched. Final classes are never guarded, * as they cannot be extended. */ - public function isTypeGuardedClass(ClassLike|ClassMethod $node): bool + public function isTypeGuardedClass(Node\Stmt\Class_|Node\Stmt\Interface_|ClassMethod $node): bool { $guardedClasses = SimpleParameterProvider::provideArrayParameter(Option::TYPE_GUARDED_CLASSES); if ($guardedClasses === []) { @@ -63,7 +62,7 @@ public function isTypeGuardedClass(ClassLike|ClassMethod $node): bool ); } - public function hasParentClassMethod(ClassMethod|MethodReflection $classMethod): bool + public function hasParentClassMethod(ClassMethod $classMethod): bool { try { $parentClassMethod = $this->resolveParentClassMethod($classMethod); diff --git a/utils/Rector/MoveAbstractRectorToChildrenRector.php b/utils/Rector/MoveAbstractRectorToChildrenRector.php deleted file mode 100644 index c5500f4c54f..00000000000 --- a/utils/Rector/MoveAbstractRectorToChildrenRector.php +++ /dev/null @@ -1,111 +0,0 @@ - - */ - private const array PROPERTIES_TO_TYPES = [ - 'phpDocInfoFactory' => PhpDocInfoFactory::class, - 'valueResolver' => ValueResolver::class, - 'betterNodeFinder' => BetterNodeFinder::class, - 'staticTypeMapper' => StaticTypeMapper::class, - ]; - - public function __construct( - private readonly ClassDependencyManipulator $classDependencyManipulator, - ) { - } - - public function getRuleDefinition(): RuleDefinition - { - return new RuleDefinition('Move parent class autowired dependency to constructor of children', []); - } - - public function getNodeTypes(): array - { - return [Class_::class]; - } - - /** - * @param Class_ $node - */ - public function refactor(Node $node): ?Node - { - if ($node->isAbstract()) { - return null; - } - - if (! $this->isObjectType($node, new ObjectType('Rector\Rector\AbstractRector'))) { - return null; - } - - $typesToAdd = []; - - // has dependency on X type? - $this->traverseNodesWithCallable($node->stmts, function (Node $node) use (&$typesToAdd) { - if (! $node instanceof PropertyFetch) { - return null; - } - - if (! $this->isName($node->var, 'this')) { - return null; - } - - foreach (self::PROPERTIES_TO_TYPES as $propertyName => $propertyType) { - if (! $this->isName($node->name, $propertyName)) { - continue; - } - - $typesToAdd[$propertyName] = $propertyType; - } - }); - - // remove already added properties - - if ($typesToAdd === []) { - return null; - } - - $hasChanged = false; - - foreach ($typesToAdd as $propertyNameToAdd => $propertyTypeToAdd) { - // skip if property already exists - if ($node->getProperty($propertyNameToAdd) instanceof Property) { - continue; - } - - $this->classDependencyManipulator->addConstructorDependency( - $node, - new PropertyMetadata($propertyNameToAdd, new ObjectType($propertyTypeToAdd)) - ); - - $hasChanged = true; - } - - if (! $hasChanged) { - return null; - } - - return $node; - } -}