From f7ef305fa1a00d3b5edfadf2a847dc613602cf88 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Fri, 23 Dec 2022 14:17:03 +0100 Subject: [PATCH 1/7] make use of Make use of unused public, type coverage and cognitive complexity split PHPStan rules --- composer.json | 4 +++- phpstan.neon | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index b0d23e179cf..a8dae80b356 100644 --- a/composer.json +++ b/composer.json @@ -61,7 +61,9 @@ "symplify/phpstan-rules": "^11.1.18", "symplify/rule-doc-generator": "^11.1.18", "symplify/vendor-patches": "^11.1.18", - "tomasvotruba/unused-public": "^0.0.23" + "tomasvotruba/cognitive-complexity": "^0.1.0", + "tomasvotruba/type-coverage": "^0.0.5", + "tomasvotruba/unused-public": "^0.0.26" }, "replace": { "rector/rector": "self.version", diff --git a/phpstan.neon b/phpstan.neon index 0f6d0a07e82..c6441e78ed8 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -9,6 +9,15 @@ parameters: constants: true methods: true + type_coverage: + param_type: 99 + return_type: 99 + property_type: 99 + + cognitive_complexity: + class: 50 + function: 12 + level: 8 # requires exact closure types From 105f54120c6c1c46fa735a708f86f1dcc91e6128 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Fri, 23 Dec 2022 14:22:14 +0100 Subject: [PATCH 2/7] debug online --- composer.json | 2 +- .../PhpDocInfo/PhpDocInfo.php | 40 +++------ .../PhpDocManipulator/PhpDocTypeChanger.php | 3 + .../PhpDocParser/ClassAnnotationMatcher.php | 3 + .../Printer/PhpDocInfoPrinter.php | 2 +- .../Parser/BetterTokenIterator.php | 46 ++++------ .../AbstractValuesAwareNode.php | 3 + .../ValueObject/RectorWithLineChange.php | 5 -- .../FluentChainMethodCallNodeAnalyzer.php | 3 + .../NodeAnalyzer/ClassChildAnalyzer.php | 24 +----- .../Parser/FileInfoParser.php | 1 + .../ValueObject/AddedFileWithContent.php | 3 + .../ArrayCallableDynamicMethod.php | 3 + .../NodeNameResolver/NodeNameResolver.php | 9 -- .../ScopeNestingComparator.php | 26 +----- packages/NodeRemoval/NodeRemover.php | 13 --- ...orBetterReflectionSourceLocatorFactory.php | 3 + .../DynamicSourceLocatorProvider.php | 3 + packages/Parallel/WorkerRunner.php | 2 +- .../NodeFactory/DoctrineAnnotationFactory.php | 3 + .../NodeFactory/PhpAttributeGroupFactory.php | 3 + .../PhpNestedAttributeGroupFactory.php | 2 +- .../Collector/NodesToAddCollector.php | 1 + .../PostRector/Rector/UseAddingPostRector.php | 1 - .../ValueObject/Type/AliasedObjectType.php | 3 + .../Type/FullyQualifiedObjectType.php | 3 + .../Type/ShortenedGenericObjectType.php | 11 +-- .../ValueObject/Type/ShortenedObjectType.php | 3 + .../Testing/Fixture/FixtureFileUpdater.php | 3 + packages/Testing/Fixture/FixtureSplitter.php | 1 + .../Testing/Fixture/FixtureTempFileDumper.php | 4 + phpstan.neon | 11 +-- .../ArgumentDefaultValueReplacer.php | 2 +- .../NodeFactory/PropertyTypeDecorator.php | 3 + ...xplicitMethodCallOverMagicGetSetRector.php | 5 +- .../Application/UseImportsRemover.php | 20 ----- rules/CodingStyle/Naming/ClassNaming.php | 6 -- .../NodeAnalyzer/UseImportNameMatcher.php | 2 +- ...assKeywordForClassNameResolutionRector.php | 30 +++---- .../ValueObject/PropertyWithPhpDocInfo.php | 5 -- ...ropertyConstructorInjectionManipulator.php | 3 + .../MatchPropertyTypeConflictingNameGuard.php | 2 +- rules/Naming/Naming/PropertyNaming.php | 1 + rules/Naming/Naming/VariableNaming.php | 2 +- .../NodeFactory/ClassFromEnumFactory.php | 3 + .../NodeManipulator/VisibilityManipulator.php | 56 ++++++------- .../Collector/MethodCallRenameCollector.php | 31 ------- .../Helper/RenameClassCallbackHandler.php | 2 +- .../Rector/MethodCall/RenameMethodRector.php | 3 - .../Rector/New_/NewArgToMethodCallRector.php | 2 +- .../Guard/PhpDocNestedAnnotationGuard.php | 2 +- .../NodeAnalyzer/CallerParamMatcher.php | 26 +++--- .../StrictReturnNewAnalyzer.php | 2 +- ...ParamTypeFromStrictTypedPropertyRector.php | 12 +-- ...FromStrictGetterMethodReturnTypeRector.php | 3 +- .../TypeInferer/ReturnTypeInferer.php | 7 +- rules/TypeDeclaration/TypeNormalizer.php | 42 ---------- .../ValueObject/AddReturnTypeDeclaration.php | 3 + .../ValueObject/AssignToVariable.php | 7 -- src/Application/ApplicationFileProcessor.php | 2 +- .../RemovedAndAddedFilesCollector.php | 2 +- src/Application/VersionResolver.php | 2 + src/Bootstrap/ExtensionConfigResolver.php | 1 + src/Configuration/ConfigurationFactory.php | 1 + src/Configuration/RectorConfigProvider.php | 6 ++ src/Configuration/ValueObjectInliner.php | 2 +- .../Output/OutputFormatterCollector.php | 12 +-- src/Error/ExceptionCorrector.php | 21 ----- src/Kernel/RectorKernel.php | 3 + src/NodeAnalyzer/CoalesceAnalyzer.php | 3 + src/NodeDecorator/NamespacedNameDecorator.php | 1 + src/NodeManipulator/ArrayManipulator.php | 9 ++ src/NodeManipulator/AssignManipulator.php | 1 + .../ClassDependencyManipulator.php | 4 + .../ClassInsertManipulator.php | 1 + src/NodeManipulator/ClassManipulator.php | 18 +--- .../ClassMethodManipulator.php | 53 ------------ src/NodeManipulator/IfManipulator.php | 22 ----- src/NodeManipulator/MethodCallManipulator.php | 3 +- src/NodeManipulator/PropertyManipulator.php | 24 +++--- src/Php/ReservedKeywordAnalyzer.php | 84 ------------------- src/PhpParser/AstResolver.php | 6 -- src/PhpParser/Node/BetterNodeFinder.php | 2 + src/PhpParser/Node/NamedVariableFactory.php | 3 + src/PhpParser/Node/NodeFactory.php | 32 ++----- src/PhpParser/Node/Value/ValueResolver.php | 1 + src/PhpParser/NodeTransformer.php | 5 ++ src/PhpParser/Parser/SimplePhpParser.php | 1 + .../Printer/BetterStandardPrinter.php | 3 + .../Printer/FormatPerservingPrinter.php | 2 + src/Reporting/MissingRectorRulesReporter.php | 40 ++++----- src/Util/ArrayParametersMerger.php | 26 ------ src/Util/Reflection/PrivatesAccessor.php | 16 ---- src/Validation/RectorAssert.php | 3 + src/ValueObject/Application/File.php | 5 -- src/ValueObject/Error/SystemError.php | 5 -- .../Util/Reflection/PrivatesAccessorTest.php | 22 ----- utils/Compiler/Unprefixer.php | 3 + 98 files changed, 282 insertions(+), 693 deletions(-) delete mode 100644 rules/Renaming/Collector/MethodCallRenameCollector.php diff --git a/composer.json b/composer.json index a8dae80b356..fc26bb7008a 100644 --- a/composer.json +++ b/composer.json @@ -49,7 +49,7 @@ "phpstan/phpstan-strict-rules": "^1.4.4", "phpstan/phpstan-webmozart-assert": "^1.2.2", "phpunit/phpunit": "^9.5.27", - "rector/phpstan-rules": "^0.6.1", + "rector/phpstan-rules": "^0.6.3", "rector/rector-debugging": "dev-main", "rector/rector-generator": "dev-main", "spatie/enum": "^3.13", diff --git a/packages/BetterPhpDocParser/PhpDocInfo/PhpDocInfo.php b/packages/BetterPhpDocParser/PhpDocInfo/PhpDocInfo.php index 4e50f75243a..c1b60585024 100644 --- a/packages/BetterPhpDocParser/PhpDocInfo/PhpDocInfo.php +++ b/packages/BetterPhpDocParser/PhpDocInfo/PhpDocInfo.php @@ -223,6 +223,9 @@ public function getByAnnotationClasses(array $classes): ?DoctrineAnnotationTagVa return $doctrineAnnotationTagValueNodes[0] ?? null; } + /** + * @api doctrine/symfony + */ public function getByAnnotationClass(string $class): ?DoctrineAnnotationTagValueNode { $doctrineAnnotationTagValueNodes = $this->phpDocNodeByTypeFinder->findDoctrineAnnotationsByClass( @@ -268,15 +271,6 @@ public function findOneByAnnotationClass(string $desiredClass): ?DoctrineAnnotat return $foundTagValueNodes[0] ?? null; } - /** - * @param class-string $desiredClass - * @return DoctrineAnnotationTagValueNode[] - */ - public function findByAnnotationClass(string $desiredClass): array - { - return $this->phpDocNodeByTypeFinder->findDoctrineAnnotationsByClass($this->phpDocNode, $desiredClass); - } - /** * @template T of \PHPStan\PhpDocParser\Ast\Node * @param class-string $typeToRemove @@ -310,25 +304,6 @@ public function removeByType(string $typeToRemove): void }); } - /** - * @return array - */ - public function getParamTypesByName(): array - { - $paramTypesByName = []; - - foreach ($this->phpDocNode->getParamTagValues() as $paramTagValueNode) { - $parameterType = $this->staticTypeMapper->mapPHPStanPhpDocTypeToPHPStanType( - $paramTagValueNode, - $this->node - ); - - $paramTypesByName[$paramTagValueNode->parameterName] = $parameterType; - } - - return $paramTypesByName; - } - public function addTagValueNode(PhpDocTagValueNode $phpDocTagValueNode): void { if ($phpDocTagValueNode instanceof DoctrineAnnotationTagValueNode) { @@ -510,6 +485,15 @@ public function resolveNameForPhpDocTagValueNode(PhpDocTagValueNode $phpDocTagVa return null; } + /** + * @param class-string $desiredClass + * @return DoctrineAnnotationTagValueNode[] + */ + private function findByAnnotationClass(string $desiredClass): array + { + return $this->phpDocNodeByTypeFinder->findDoctrineAnnotationsByClass($this->phpDocNode, $desiredClass); + } + private function getTypeOrMixed(?PhpDocTagValueNode $phpDocTagValueNode): MixedType | Type { if ($phpDocTagValueNode === null) { diff --git a/packages/BetterPhpDocParser/PhpDocManipulator/PhpDocTypeChanger.php b/packages/BetterPhpDocParser/PhpDocManipulator/PhpDocTypeChanger.php index 530d87d7cbe..d122aa82356 100644 --- a/packages/BetterPhpDocParser/PhpDocManipulator/PhpDocTypeChanger.php +++ b/packages/BetterPhpDocParser/PhpDocManipulator/PhpDocTypeChanger.php @@ -240,6 +240,9 @@ public function copyPropertyDocToParam(Property $property, Param $param): void $this->processKeepComments($property, $param); } + /** + * @api doctrine + */ public function changeVarTypeNode(PhpDocInfo $phpDocInfo, TypeNode $typeNode): void { // add completely new one diff --git a/packages/BetterPhpDocParser/PhpDocParser/ClassAnnotationMatcher.php b/packages/BetterPhpDocParser/PhpDocParser/ClassAnnotationMatcher.php index ffc7049d5d7..10a3a3827e1 100644 --- a/packages/BetterPhpDocParser/PhpDocParser/ClassAnnotationMatcher.php +++ b/packages/BetterPhpDocParser/PhpDocParser/ClassAnnotationMatcher.php @@ -32,6 +32,9 @@ public function __construct( ) { } + /** + * @api doctrine + */ public function resolveTagToKnownFullyQualifiedName(string $tag, Property $property): ?string { return $this->_resolveTagFullyQualifiedName($tag, $property, true); diff --git a/packages/BetterPhpDocParser/Printer/PhpDocInfoPrinter.php b/packages/BetterPhpDocParser/Printer/PhpDocInfoPrinter.php index 8be78bad53e..39b8744ee4e 100644 --- a/packages/BetterPhpDocParser/Printer/PhpDocInfoPrinter.php +++ b/packages/BetterPhpDocParser/Printer/PhpDocInfoPrinter.php @@ -135,7 +135,7 @@ public function printFormatPreserving(PhpDocInfo $phpDocInfo): string return Strings::replace($phpDocString, self::CALLABLE_REGEX, 'callable('); } - public function getCurrentPhpDocInfo(): PhpDocInfo + private function getCurrentPhpDocInfo(): PhpDocInfo { if ($this->phpDocInfo === null) { throw new ShouldNotHappenException(); diff --git a/packages/BetterPhpDocParser/ValueObject/Parser/BetterTokenIterator.php b/packages/BetterPhpDocParser/ValueObject/Parser/BetterTokenIterator.php index 62ada7ccaef..f99291846c2 100644 --- a/packages/BetterPhpDocParser/ValueObject/Parser/BetterTokenIterator.php +++ b/packages/BetterPhpDocParser/ValueObject/Parser/BetterTokenIterator.php @@ -97,34 +97,6 @@ public function printFromTo(int $from, int $to): string return $content; } - public function print(): string - { - $content = ''; - foreach ($this->getTokens() as $token) { - $content .= $token[0]; - } - - return $content; - } - - public function nextTokenType(): ?int - { - $tokens = $this->getTokens(); - - // does next token exist? - $nextIndex = $this->currentPosition() + 1; - if (! isset($tokens[$nextIndex])) { - return null; - } - - $this->pushSavePoint(); - $this->next(); - $nextTokenType = $this->currentTokenType(); - $this->rollback(); - - return $nextTokenType; - } - public function currentPosition(): int { return $this->privatesAccessor->getPrivateProperty($this, self::INDEX); @@ -161,4 +133,22 @@ public function containsTokenType(int $type): bool return false; } + + private function nextTokenType(): ?int + { + $tokens = $this->getTokens(); + + // does next token exist? + $nextIndex = $this->currentPosition() + 1; + if (! isset($tokens[$nextIndex])) { + return null; + } + + $this->pushSavePoint(); + $this->next(); + $nextTokenType = $this->currentTokenType(); + $this->rollback(); + + return $nextTokenType; + } } diff --git a/packages/BetterPhpDocParser/ValueObject/PhpDoc/DoctrineAnnotation/AbstractValuesAwareNode.php b/packages/BetterPhpDocParser/ValueObject/PhpDoc/DoctrineAnnotation/AbstractValuesAwareNode.php index 05edcb7efbb..c03ee49cf9f 100644 --- a/packages/BetterPhpDocParser/ValueObject/PhpDoc/DoctrineAnnotation/AbstractValuesAwareNode.php +++ b/packages/BetterPhpDocParser/ValueObject/PhpDoc/DoctrineAnnotation/AbstractValuesAwareNode.php @@ -25,6 +25,9 @@ public function __construct( ) { } + /** + * @api + */ public function removeValue(string $desiredKey): void { foreach ($this->values as $key => $value) { diff --git a/packages/ChangesReporting/ValueObject/RectorWithLineChange.php b/packages/ChangesReporting/ValueObject/RectorWithLineChange.php index 3b017f9ca9f..96b61fc5482 100644 --- a/packages/ChangesReporting/ValueObject/RectorWithLineChange.php +++ b/packages/ChangesReporting/ValueObject/RectorWithLineChange.php @@ -47,11 +47,6 @@ public function getRectorClass(): string return $this->rectorClass; } - public function getLine(): int - { - return $this->line; - } - /** * @param array $json */ diff --git a/packages/Defluent/NodeAnalyzer/FluentChainMethodCallNodeAnalyzer.php b/packages/Defluent/NodeAnalyzer/FluentChainMethodCallNodeAnalyzer.php index 61d3155e359..a5fe23d81d7 100644 --- a/packages/Defluent/NodeAnalyzer/FluentChainMethodCallNodeAnalyzer.php +++ b/packages/Defluent/NodeAnalyzer/FluentChainMethodCallNodeAnalyzer.php @@ -15,6 +15,9 @@ */ final class FluentChainMethodCallNodeAnalyzer { + /** + * @api doctrine + */ public function resolveRootMethodCall(MethodCall $methodCall): ?MethodCall { $callerNode = $methodCall->var; diff --git a/packages/FamilyTree/NodeAnalyzer/ClassChildAnalyzer.php b/packages/FamilyTree/NodeAnalyzer/ClassChildAnalyzer.php index 267e09feb66..fdad7e55b7d 100644 --- a/packages/FamilyTree/NodeAnalyzer/ClassChildAnalyzer.php +++ b/packages/FamilyTree/NodeAnalyzer/ClassChildAnalyzer.php @@ -5,10 +5,7 @@ namespace Rector\FamilyTree\NodeAnalyzer; use PHPStan\Reflection\ClassReflection; -use PHPStan\Reflection\ParametersAcceptorSelector; use PHPStan\Reflection\Php\PhpMethodReflection; -use PHPStan\Type\MixedType; -use PHPStan\Type\Type; use Rector\FamilyTree\Reflection\FamilyRelationsAnalyzer; final class ClassChildAnalyzer @@ -65,29 +62,10 @@ public function hasAbstractParentClassMethod(ClassReflection $classReflection, s return false; } - public function resolveParentClassMethodReturnType(ClassReflection $classReflection, string $methodName): Type - { - $parentClassMethods = $this->resolveParentClassMethods($classReflection, $methodName); - if ($parentClassMethods === []) { - return new MixedType(); - } - - foreach ($parentClassMethods as $parentClassMethod) { - $parametersAcceptor = ParametersAcceptorSelector::selectSingle($parentClassMethod->getVariants()); - $nativeReturnType = $parametersAcceptor->getNativeReturnType(); - - if (! $nativeReturnType instanceof MixedType) { - return $nativeReturnType; - } - } - - return new MixedType(); - } - /** * @return PhpMethodReflection[] */ - public function resolveParentClassMethods(ClassReflection $classReflection, string $methodName): array + private function resolveParentClassMethods(ClassReflection $classReflection, string $methodName): array { $parentClassMethods = []; $parents = array_merge($classReflection->getParents(), $classReflection->getInterfaces()); diff --git a/packages/FileSystemRector/Parser/FileInfoParser.php b/packages/FileSystemRector/Parser/FileInfoParser.php index 79240a818c6..6e8b9b36943 100644 --- a/packages/FileSystemRector/Parser/FileInfoParser.php +++ b/packages/FileSystemRector/Parser/FileInfoParser.php @@ -24,6 +24,7 @@ public function __construct( } /** + * @api tests only * @return Stmt[] */ public function parseFileInfoToNodesAndDecorate(string $filePath): array diff --git a/packages/FileSystemRector/ValueObject/AddedFileWithContent.php b/packages/FileSystemRector/ValueObject/AddedFileWithContent.php index e7f912c6315..34c630fbca0 100644 --- a/packages/FileSystemRector/ValueObject/AddedFileWithContent.php +++ b/packages/FileSystemRector/ValueObject/AddedFileWithContent.php @@ -7,6 +7,9 @@ use Rector\Core\Exception\ShouldNotHappenException; use Rector\FileSystemRector\Contract\AddedFileInterface; +/** + * @api + */ final class AddedFileWithContent implements AddedFileInterface { public function __construct( diff --git a/packages/NodeCollector/ValueObject/ArrayCallableDynamicMethod.php b/packages/NodeCollector/ValueObject/ArrayCallableDynamicMethod.php index dd9b82a80aa..d4c88028724 100644 --- a/packages/NodeCollector/ValueObject/ArrayCallableDynamicMethod.php +++ b/packages/NodeCollector/ValueObject/ArrayCallableDynamicMethod.php @@ -7,6 +7,9 @@ use PhpParser\Node\Expr; use Rector\Core\Validation\RectorAssert; +/** + * @api + */ final class ArrayCallableDynamicMethod { public function __construct( diff --git a/packages/NodeNameResolver/NodeNameResolver.php b/packages/NodeNameResolver/NodeNameResolver.php index abd16d0884d..4f71d3c6908 100644 --- a/packages/NodeNameResolver/NodeNameResolver.php +++ b/packages/NodeNameResolver/NodeNameResolver.php @@ -182,15 +182,6 @@ public function getShortName(string | Name | Identifier | ClassLike $name): stri return $this->classNaming->getShortName($name); } - /** - * @param array $renameMap - */ - public function matchNameFromMap(Node $node, array $renameMap): ?string - { - $name = $this->getName($node); - return $renameMap[$name] ?? null; - } - public function isStringName(string $resolvedName, string $desiredName): bool { if ($desiredName === '') { diff --git a/packages/NodeNestingScope/ScopeNestingComparator.php b/packages/NodeNestingScope/ScopeNestingComparator.php index 8bf0db5c187..05c26be94c3 100644 --- a/packages/NodeNestingScope/ScopeNestingComparator.php +++ b/packages/NodeNestingScope/ScopeNestingComparator.php @@ -9,7 +9,6 @@ use PhpParser\Node\FunctionLike; use PhpParser\Node\Stmt\Else_; use PhpParser\Node\Stmt\If_; -use PhpParser\Node\Stmt\Return_; use Rector\Core\PhpParser\Comparing\NodeComparator; use Rector\Core\PhpParser\Node\BetterNodeFinder; use Rector\NodeNestingScope\ValueObject\ControlStructure; @@ -27,24 +26,6 @@ public function __construct( ) { } - public function areReturnScopeNested(Return_ $return, Node $secondNodeScopeNode): bool - { - $firstNodeScopeNode = $this->betterNodeFinder->findParentByTypes( - $return, - ControlStructure::RETURN_ISOLATING_SCOPE_NODE_TYPES - ); - - return $this->nodeComparator->areNodesEqual($firstNodeScopeNode, $secondNodeScopeNode); - } - - public function areScopeNestingEqual(Node $firstNode, Node $secondNode): bool - { - $firstNodeScopeNode = $this->findParentControlStructure($firstNode); - $secondNodeScopeNode = $this->findParentControlStructure($secondNode); - - return $this->nodeComparator->areNodesEqual($firstNodeScopeNode, $secondNodeScopeNode); - } - public function isNodeConditionallyScoped(Expr $expr): bool { $foundParent = $this->betterNodeFinder->findParentByTypes( @@ -72,7 +53,7 @@ public function isNodeConditionallyScoped(Expr $expr): bool return false; } - public function isInBothIfElseBranch(Node $foundParentNode, Expr $seekedExpr): bool + private function isInBothIfElseBranch(Node $foundParentNode, Expr $seekedExpr): bool { if ($foundParentNode instanceof Else_) { return $this->nodeComparator->isNodeEqual($seekedExpr, $this->doubleIfBranchExprs); @@ -103,9 +84,4 @@ public function isInBothIfElseBranch(Node $foundParentNode, Expr $seekedExpr): b return false; } - - private function findParentControlStructure(Node $node): ?Node - { - return $this->betterNodeFinder->findParentByTypes($node, ControlStructure::BREAKING_SCOPE_NODE_TYPES); - } } diff --git a/packages/NodeRemoval/NodeRemover.php b/packages/NodeRemoval/NodeRemover.php index 028ba648d6b..4aecc0d98f9 100644 --- a/packages/NodeRemoval/NodeRemover.php +++ b/packages/NodeRemoval/NodeRemover.php @@ -5,7 +5,6 @@ namespace Rector\NodeRemoval; use PhpParser\Node; -use PhpParser\Node\Expr\Closure; use PhpParser\Node\Expr\FuncCall; use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Expr\StaticCall; @@ -63,18 +62,6 @@ public function removeNodes(array $nodes): void } } - public function removeStmt(Closure | ClassMethod | Function_ $functionLike, int $key): void - { - if ($functionLike->stmts === null) { - throw new ShouldNotHappenException(); - } - - // notify about remove node - $this->rectorChangeCollector->notifyNodeFileInfo($functionLike->stmts[$key]); - - unset($functionLike->stmts[$key]); - } - public function removeParam(ClassMethod $classMethod, int | Param $keyOrParam): void { $key = $keyOrParam instanceof Param ? $keyOrParam->getAttribute(AttributeKey::PARAMETER_POSITION) : $keyOrParam; diff --git a/packages/NodeTypeResolver/Reflection/BetterReflection/RectorBetterReflectionSourceLocatorFactory.php b/packages/NodeTypeResolver/Reflection/BetterReflection/RectorBetterReflectionSourceLocatorFactory.php index b4b236bbfe4..fc2678f2148 100644 --- a/packages/NodeTypeResolver/Reflection/BetterReflection/RectorBetterReflectionSourceLocatorFactory.php +++ b/packages/NodeTypeResolver/Reflection/BetterReflection/RectorBetterReflectionSourceLocatorFactory.php @@ -9,6 +9,9 @@ use PHPStan\Reflection\BetterReflection\BetterReflectionSourceLocatorFactory; use Rector\NodeTypeResolver\Reflection\BetterReflection\SourceLocator\IntermediateSourceLocator; +/** + * @api used on phpstan config factory + */ final class RectorBetterReflectionSourceLocatorFactory { public function __construct( diff --git a/packages/NodeTypeResolver/Reflection/BetterReflection/SourceLocatorProvider/DynamicSourceLocatorProvider.php b/packages/NodeTypeResolver/Reflection/BetterReflection/SourceLocatorProvider/DynamicSourceLocatorProvider.php index fab1a1682f6..96df3124948 100644 --- a/packages/NodeTypeResolver/Reflection/BetterReflection/SourceLocatorProvider/DynamicSourceLocatorProvider.php +++ b/packages/NodeTypeResolver/Reflection/BetterReflection/SourceLocatorProvider/DynamicSourceLocatorProvider.php @@ -14,6 +14,9 @@ use Rector\Testing\PHPUnit\StaticPHPUnitEnvironment; use Webmozart\Assert\Assert; +/** + * @api phpstan external + */ final class DynamicSourceLocatorProvider implements SourceLocatorProviderInterface { /** diff --git a/packages/Parallel/WorkerRunner.php b/packages/Parallel/WorkerRunner.php index 7eace8da892..e55ecab4b96 100644 --- a/packages/Parallel/WorkerRunner.php +++ b/packages/Parallel/WorkerRunner.php @@ -133,7 +133,7 @@ public function run(Encoder $encoder, Decoder $decoder, Configuration $configura * @param array{system_errors: SystemError[], file_diffs: FileDiff[]}|mixed[] $errorAndFileDiffs * @return array{system_errors: SystemError[], file_diffs: FileDiff[]} */ - public function processFiles(File $file, Configuration $configuration, array $errorAndFileDiffs): array + private function processFiles(File $file, Configuration $configuration, array $errorAndFileDiffs): array { foreach ($this->fileProcessors as $fileProcessor) { if (! $fileProcessor->supports($file, $configuration)) { diff --git a/packages/PhpAttribute/NodeFactory/DoctrineAnnotationFactory.php b/packages/PhpAttribute/NodeFactory/DoctrineAnnotationFactory.php index 4bd0e2603b8..5e25f45347a 100644 --- a/packages/PhpAttribute/NodeFactory/DoctrineAnnotationFactory.php +++ b/packages/PhpAttribute/NodeFactory/DoctrineAnnotationFactory.php @@ -19,6 +19,9 @@ public function __construct( ) { } + /** + * @api downgrade + */ public function createFromAttribute(Attribute $attribute, string $className): DoctrineAnnotationTagValueNode { $items = $this->createItemsFromArgs($attribute->args); diff --git a/packages/PhpAttribute/NodeFactory/PhpAttributeGroupFactory.php b/packages/PhpAttribute/NodeFactory/PhpAttributeGroupFactory.php index 03d65287f7d..f2bfac0b27c 100644 --- a/packages/PhpAttribute/NodeFactory/PhpAttributeGroupFactory.php +++ b/packages/PhpAttribute/NodeFactory/PhpAttributeGroupFactory.php @@ -45,6 +45,7 @@ public function createFromClass(string $attributeClass): AttributeGroup } /** + * @api tests * @param mixed[] $items */ public function createFromClassWithItems(string $attributeClass, array $items): AttributeGroup @@ -84,6 +85,8 @@ public function create( } /** + * @api tests + * * @param ArrayItemNode[]|mixed[] $items * @return Arg[] */ diff --git a/packages/PhpAttribute/NodeFactory/PhpNestedAttributeGroupFactory.php b/packages/PhpAttribute/NodeFactory/PhpNestedAttributeGroupFactory.php index 2aac64cdb9d..1fe3435bf21 100644 --- a/packages/PhpAttribute/NodeFactory/PhpNestedAttributeGroupFactory.php +++ b/packages/PhpAttribute/NodeFactory/PhpNestedAttributeGroupFactory.php @@ -115,7 +115,7 @@ public function createNested( /** * @return Arg[] */ - public function createAttributeArgs( + private function createAttributeArgs( DoctrineAnnotationTagValueNode $nestedDoctrineAnnotationTagValueNode, NestedAnnotationToAttribute $nestedAnnotationToAttribute ): array { diff --git a/packages/PostRector/Collector/NodesToAddCollector.php b/packages/PostRector/Collector/NodesToAddCollector.php index 63ee68ef2da..dc39d516387 100644 --- a/packages/PostRector/Collector/NodesToAddCollector.php +++ b/packages/PostRector/Collector/NodesToAddCollector.php @@ -132,6 +132,7 @@ public function clearNodesToAddBefore(Node $node): void } /** + * @api downgrade * @deprecated Return created nodes right in refactor() method to keep context instead. * @param Node[] $newNodes */ diff --git a/packages/PostRector/Rector/UseAddingPostRector.php b/packages/PostRector/Rector/UseAddingPostRector.php index b54db57f97a..c66a892b45d 100644 --- a/packages/PostRector/Rector/UseAddingPostRector.php +++ b/packages/PostRector/Rector/UseAddingPostRector.php @@ -66,7 +66,6 @@ public function beforeTraverse(array $nodes): array $namespace = $this->betterNodeFinder->findFirstInstanceOf($nodes, Namespace_::class); if ($namespace instanceof Namespace_) { // first clean - //$this->useImportsRemover->removeImportsFromNamespace($namespace, $removedShortUses); // then add, to prevent adding + removing false positive of same short use $this->useImportsAdder->addImportsToNamespace($namespace, $useImportTypes, $functionUseImportTypes); diff --git a/packages/StaticTypeMapper/ValueObject/Type/AliasedObjectType.php b/packages/StaticTypeMapper/ValueObject/Type/AliasedObjectType.php index d9d9542bb15..19d16dbd737 100644 --- a/packages/StaticTypeMapper/ValueObject/Type/AliasedObjectType.php +++ b/packages/StaticTypeMapper/ValueObject/Type/AliasedObjectType.php @@ -12,6 +12,9 @@ use PHPStan\Type\TypeWithClassName; use Rector\NodeTypeResolver\Node\AttributeKey; +/** + * @api + */ final class AliasedObjectType extends ObjectType { public function __construct( diff --git a/packages/StaticTypeMapper/ValueObject/Type/FullyQualifiedObjectType.php b/packages/StaticTypeMapper/ValueObject/Type/FullyQualifiedObjectType.php index f78673c579a..2c77985abee 100644 --- a/packages/StaticTypeMapper/ValueObject/Type/FullyQualifiedObjectType.php +++ b/packages/StaticTypeMapper/ValueObject/Type/FullyQualifiedObjectType.php @@ -11,6 +11,9 @@ use PHPStan\Type\ObjectType; use Rector\NodeTypeResolver\Node\AttributeKey; +/** + * @api + */ final class FullyQualifiedObjectType extends ObjectType { public function getShortNameType(): ShortenedObjectType diff --git a/packages/StaticTypeMapper/ValueObject/Type/ShortenedGenericObjectType.php b/packages/StaticTypeMapper/ValueObject/Type/ShortenedGenericObjectType.php index 974c41525d7..fa4f6b0decd 100644 --- a/packages/StaticTypeMapper/ValueObject/Type/ShortenedGenericObjectType.php +++ b/packages/StaticTypeMapper/ValueObject/Type/ShortenedGenericObjectType.php @@ -8,6 +8,9 @@ use PHPStan\Type\Generic\GenericObjectType; use PHPStan\Type\Type; +/** + * @api + */ final class ShortenedGenericObjectType extends GenericObjectType { /** @@ -31,12 +34,4 @@ public function getShortName(): string { return $this->getClassName(); } - - /** - * @return class-string - */ - public function getFullyQualifiedName(): string - { - return $this->fullyQualifiedName; - } } diff --git a/packages/StaticTypeMapper/ValueObject/Type/ShortenedObjectType.php b/packages/StaticTypeMapper/ValueObject/Type/ShortenedObjectType.php index 3f0a35d2c33..76beff0939b 100644 --- a/packages/StaticTypeMapper/ValueObject/Type/ShortenedObjectType.php +++ b/packages/StaticTypeMapper/ValueObject/Type/ShortenedObjectType.php @@ -8,6 +8,9 @@ use PHPStan\Type\ObjectType; use PHPStan\Type\Type; +/** + * @api + */ final class ShortenedObjectType extends ObjectType { /** diff --git a/packages/Testing/Fixture/FixtureFileUpdater.php b/packages/Testing/Fixture/FixtureFileUpdater.php index a1f1f58222b..e8917c6197e 100644 --- a/packages/Testing/Fixture/FixtureFileUpdater.php +++ b/packages/Testing/Fixture/FixtureFileUpdater.php @@ -8,6 +8,9 @@ final class FixtureFileUpdater { + /** + * @api + */ public static function updateFixtureContent( string $originalFilePath, string $changedContent, diff --git a/packages/Testing/Fixture/FixtureSplitter.php b/packages/Testing/Fixture/FixtureSplitter.php index c2c8600c0c6..1b2eff9413a 100644 --- a/packages/Testing/Fixture/FixtureSplitter.php +++ b/packages/Testing/Fixture/FixtureSplitter.php @@ -10,6 +10,7 @@ final class FixtureSplitter { /** + * @api * @var string * @see https://regex101.com/r/zZDoyy/1 */ diff --git a/packages/Testing/Fixture/FixtureTempFileDumper.php b/packages/Testing/Fixture/FixtureTempFileDumper.php index 0a6b8b9acd6..e08bdddc760 100644 --- a/packages/Testing/Fixture/FixtureTempFileDumper.php +++ b/packages/Testing/Fixture/FixtureTempFileDumper.php @@ -8,6 +8,7 @@ final class FixtureTempFileDumper { /** + * @api * @var string */ public const TEMP_FIXTURE_DIRECTORY = '/rector/tests_fixture_'; @@ -21,6 +22,9 @@ public static function dump(string $fileContents, string $suffix = 'php'): strin return $temporaryFileName; } + /** + * @api + */ public static function getTempDirectory(): string { return sys_get_temp_dir() . self::TEMP_FIXTURE_DIRECTORY; diff --git a/phpstan.neon b/phpstan.neon index c6441e78ed8..2cbe7a85c47 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -16,7 +16,7 @@ parameters: cognitive_complexity: class: 50 - function: 12 + function: 10 level: 8 @@ -711,12 +711,6 @@ parameters: message: '#Creating new PHPStan\\Parser\\(CachedParser|SimpleParser) is not covered by backward compatibility promise\. The class might change in a minor PHPStan version#' path: packages/PhpDocParser/PhpParser/SmartPhpParserFactory.php - # used in a trait - - '#Class constant "TEMP_FIXTURE_DIRECTORY" is never used#' - - # used in abstract test case - - '#Class constant "SPLIT_LINE_REGEX" is never used#' - - message: '#Only booleans are allowed in a negated boolean, string\|false given#' path: packages/Testing/Fixture/FixtureFileUpdater.php @@ -858,9 +852,6 @@ parameters: - '#Cognitive complexity for "Rector\\Utils\\ChangelogGenerator\\Changelog\\ChangelogContentsFactory\:\:create\(\)" is 11, keep it under 10#' - - - message: '#"Tests" namespace cannot be used outside of "tests" directory#' - path: rules-tests - message: '#Parameter \#1 \$phpVersion of method Rector\\Config\\RectorConfig\:\:phpVersion\(\) expects 50200\|50300\|50400\|50500\|50600\|70000\|70100\|70200\|70300\|70400\|80000\|80100\|80200\|100000, (.*?) given#' path: rules-tests diff --git a/rules/Arguments/ArgumentDefaultValueReplacer.php b/rules/Arguments/ArgumentDefaultValueReplacer.php index 506484f0c5a..332cd398ff3 100644 --- a/rules/Arguments/ArgumentDefaultValueReplacer.php +++ b/rules/Arguments/ArgumentDefaultValueReplacer.php @@ -45,7 +45,7 @@ public function processReplaces( return $this->processArgs($node, $replaceArgumentDefaultValue); } - public function isDefaultValueMatched(?Expr $expr, mixed $value): bool + private function isDefaultValueMatched(?Expr $expr, mixed $value): bool { // allow any values before, also allow param without default value if ($value === ReplaceArgumentDefaultValue::ANY_VALUE_BEFORE) { diff --git a/rules/CodeQuality/NodeFactory/PropertyTypeDecorator.php b/rules/CodeQuality/NodeFactory/PropertyTypeDecorator.php index 4a7d4296c8c..75a5dcf83ba 100644 --- a/rules/CodeQuality/NodeFactory/PropertyTypeDecorator.php +++ b/rules/CodeQuality/NodeFactory/PropertyTypeDecorator.php @@ -40,6 +40,9 @@ public function decorateProperty(Property $property, Type $propertyType): void $this->decoratePropertyWithType($property, $propertyType); } + /** + * @api downgrade + */ public function decoratePropertyWithDocBlock(Property $property, ComplexType|Identifier|Name $typeNode): void { $phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($property); diff --git a/rules/CodeQuality/Rector/PropertyFetch/ExplicitMethodCallOverMagicGetSetRector.php b/rules/CodeQuality/Rector/PropertyFetch/ExplicitMethodCallOverMagicGetSetRector.php index 69105840114..71a8b75a9ae 100644 --- a/rules/CodeQuality/Rector/PropertyFetch/ExplicitMethodCallOverMagicGetSetRector.php +++ b/rules/CodeQuality/Rector/PropertyFetch/ExplicitMethodCallOverMagicGetSetRector.php @@ -118,9 +118,10 @@ public function refactorWithScope(Node $node, Scope $scope): ?Node /** * @return string[] */ - public function resolvePossibleGetMethodNames(string $propertyName): array + private function resolvePossibleGetMethodNames(string $propertyName): array { - return ['get' . ucfirst($propertyName), 'has' . ucfirst($propertyName), 'is' . ucfirst($propertyName)]; + $upperPropertyName = ucfirst($propertyName); + return ['get' . $upperPropertyName, 'has' . $upperPropertyName, 'is' . $upperPropertyName]; } private function shouldSkipPropertyFetch(PropertyFetch $propertyFetch): bool diff --git a/rules/CodingStyle/Application/UseImportsRemover.php b/rules/CodingStyle/Application/UseImportsRemover.php index 3fbd446ec68..c3953d07d0a 100644 --- a/rules/CodingStyle/Application/UseImportsRemover.php +++ b/rules/CodingStyle/Application/UseImportsRemover.php @@ -5,7 +5,6 @@ namespace Rector\CodingStyle\Application; use PhpParser\Node\Stmt; -use PhpParser\Node\Stmt\Namespace_; use PhpParser\Node\Stmt\Use_; final class UseImportsRemover @@ -33,25 +32,6 @@ public function removeImportsFromStmts(array $stmts, array $removedShortUses): a return $stmts; } - /** - * @param string[] $removedShortUses - */ - public function removeImportsFromNamespace(Namespace_ $namespace, array $removedShortUses): void - { - foreach ($namespace->stmts as $namespaceKey => $stmt) { - if (! $stmt instanceof Use_) { - continue; - } - - $this->removeUseFromUse($removedShortUses, $stmt); - - // nothing left → remove - if ($stmt->uses === []) { - unset($namespace->stmts[$namespaceKey]); - } - } - } - /** * @param string[] $removedShortUses */ diff --git a/rules/CodingStyle/Naming/ClassNaming.php b/rules/CodingStyle/Naming/ClassNaming.php index be318cc8918..594c56e1faf 100644 --- a/rules/CodingStyle/Naming/ClassNaming.php +++ b/rules/CodingStyle/Naming/ClassNaming.php @@ -11,12 +11,6 @@ final class ClassNaming { - public function getVariableName(string | Name | Identifier $name): string - { - $shortName = $this->getShortName($name); - return lcfirst($shortName); - } - public function getShortName(string | Name | Identifier | ClassLike $name): string { if ($name instanceof ClassLike) { diff --git a/rules/CodingStyle/NodeAnalyzer/UseImportNameMatcher.php b/rules/CodingStyle/NodeAnalyzer/UseImportNameMatcher.php index d21044a7c17..4ce0b1e2630 100644 --- a/rules/CodingStyle/NodeAnalyzer/UseImportNameMatcher.php +++ b/rules/CodingStyle/NodeAnalyzer/UseImportNameMatcher.php @@ -61,7 +61,7 @@ public function matchNameWithUses(string $tag, array $uses): ?string return null; } - public function resolveName(string $prefix, string $tag, UseUse $useUse): string + private function resolveName(string $prefix, string $tag, UseUse $useUse): string { // useuse can be renamed on the fly, so just in case, use the original one $originalUseUse = $useUse->getAttribute(AttributeKey::ORIGINAL_NODE); diff --git a/rules/CodingStyle/Rector/String_/UseClassKeywordForClassNameResolutionRector.php b/rules/CodingStyle/Rector/String_/UseClassKeywordForClassNameResolutionRector.php index 1a4a4dab03b..c092a227dea 100644 --- a/rules/CodingStyle/Rector/String_/UseClassKeywordForClassNameResolutionRector.php +++ b/rules/CodingStyle/Rector/String_/UseClassKeywordForClassNameResolutionRector.php @@ -83,10 +83,24 @@ public function refactor(Node $node): ?Node return $this->nodeFactory->createConcat($exprsToConcat); } + /** + * @param string[] $classNames + * @return mixed[] + */ + private function getParts(String_ $string, array $classNames): array + { + $quotedClassNames = array_map('preg_quote', $classNames); + + // @see https://regex101.com/r/8nGS0F/1 + $parts = Strings::split($string->value, '#(' . implode('|', $quotedClassNames) . ')#'); + + return array_filter($parts, static fn (string $className): bool => $className !== ''); + } + /** * @return string[] */ - public function getExistingClasses(String_ $string): array + private function getExistingClasses(String_ $string): array { /** @var mixed[] $matches */ $matches = Strings::matchAll($string->value, self::CLASS_BEFORE_STATIC_ACCESS_REGEX, PREG_PATTERN_ORDER); @@ -107,20 +121,6 @@ public function getExistingClasses(String_ $string): array return $classNames; } - /** - * @param string[] $classNames - * @return mixed[] - */ - public function getParts(String_ $string, array $classNames): array - { - $quotedClassNames = array_map('preg_quote', $classNames); - - // @see https://regex101.com/r/8nGS0F/1 - $parts = Strings::split($string->value, '#(' . implode('|', $quotedClassNames) . ')#'); - - return array_filter($parts, static fn (string $className): bool => $className !== ''); - } - /** * @param string[] $parts * @return ClassConstFetch[]|String_[] diff --git a/rules/Compatibility/ValueObject/PropertyWithPhpDocInfo.php b/rules/Compatibility/ValueObject/PropertyWithPhpDocInfo.php index 3d1c7c5a07e..a795945c303 100644 --- a/rules/Compatibility/ValueObject/PropertyWithPhpDocInfo.php +++ b/rules/Compatibility/ValueObject/PropertyWithPhpDocInfo.php @@ -29,11 +29,6 @@ public function getPhpDocInfo(): PhpDocInfo return $this->phpDocInfo; } - public function getPropertyName(): string - { - return $this->propertyName; - } - public function getParamTagValueNode(): ParamTagValueNode { $varTagValueNode = $this->phpDocInfo->getVarTagValueNode(); diff --git a/rules/DependencyInjection/NodeManipulator/PropertyConstructorInjectionManipulator.php b/rules/DependencyInjection/NodeManipulator/PropertyConstructorInjectionManipulator.php index 17583afb082..8433e6f6408 100644 --- a/rules/DependencyInjection/NodeManipulator/PropertyConstructorInjectionManipulator.php +++ b/rules/DependencyInjection/NodeManipulator/PropertyConstructorInjectionManipulator.php @@ -29,6 +29,9 @@ public function __construct( ) { } + /** + * @api symfony + */ public function refactor( Property $property, Type $type, diff --git a/rules/Naming/Guard/PropertyConflictingNameGuard/MatchPropertyTypeConflictingNameGuard.php b/rules/Naming/Guard/PropertyConflictingNameGuard/MatchPropertyTypeConflictingNameGuard.php index 66619cf0e75..c908fbb9a09 100644 --- a/rules/Naming/Guard/PropertyConflictingNameGuard/MatchPropertyTypeConflictingNameGuard.php +++ b/rules/Naming/Guard/PropertyConflictingNameGuard/MatchPropertyTypeConflictingNameGuard.php @@ -28,7 +28,7 @@ public function isConflicting(PropertyRename $propertyRename): bool /** * @return string[] */ - public function resolve(ClassLike $classLike): array + private function resolve(ClassLike $classLike): array { $expectedNames = []; foreach ($classLike->getProperties() as $property) { diff --git a/rules/Naming/Naming/PropertyNaming.php b/rules/Naming/Naming/PropertyNaming.php index 99f1c6ccf8a..e9fd78e3099 100644 --- a/rules/Naming/Naming/PropertyNaming.php +++ b/rules/Naming/Naming/PropertyNaming.php @@ -124,6 +124,7 @@ public function fqnToVariableName(ThisType | ObjectType | string $objectType): s } /** + * @api symfony * @see https://stackoverflow.com/a/2792045/1348344 */ public function underscoreToName(string $underscoreName): string diff --git a/rules/Naming/Naming/VariableNaming.php b/rules/Naming/Naming/VariableNaming.php index 998156c183f..b1e57f562d2 100644 --- a/rules/Naming/Naming/VariableNaming.php +++ b/rules/Naming/Naming/VariableNaming.php @@ -90,7 +90,7 @@ public function resolveFromFuncCallFirstArgumentWithSuffix( return $this->createCountedValueName($bareName, $scope); } - public function resolveFromNodeAndType(Node $node, Type $type): ?string + private function resolveFromNodeAndType(Node $node, Type $type): ?string { $variableName = $this->resolveBareFromNode($node); if ($variableName === null) { diff --git a/rules/Php81/NodeFactory/ClassFromEnumFactory.php b/rules/Php81/NodeFactory/ClassFromEnumFactory.php index 9ed350b8e68..839cf5f899b 100644 --- a/rules/Php81/NodeFactory/ClassFromEnumFactory.php +++ b/rules/Php81/NodeFactory/ClassFromEnumFactory.php @@ -21,6 +21,9 @@ public function __construct( ) { } + /** + * @api downgrade + */ public function createFromEnum(Enum_ $enum): Class_ { $shortClassName = $this->nodeNameResolver->getShortName($enum); diff --git a/rules/Privatization/NodeManipulator/VisibilityManipulator.php b/rules/Privatization/NodeManipulator/VisibilityManipulator.php index 3c06568cefb..b06331e20cb 100644 --- a/rules/Privatization/NodeManipulator/VisibilityManipulator.php +++ b/rules/Privatization/NodeManipulator/VisibilityManipulator.php @@ -42,11 +42,6 @@ public function makeNonStatic(ClassMethod | Property $node): void $node->flags -= Class_::MODIFIER_STATIC; } - public function makeAbstract(ClassMethod | Class_ $node): void - { - $this->addVisibilityFlag($node, Visibility::ABSTRACT); - } - /** * @api */ @@ -76,30 +71,6 @@ public function makeNonFinal(Class_ | ClassMethod $node): void $node->flags -= Class_::MODIFIER_FINAL; } - /** - * This way "abstract", "static", "final" are kept - */ - public function removeVisibility(ClassMethod | Property | ClassConst $node): void - { - // no modifier - if ($node->flags === 0) { - return; - } - - if ($node->isPublic()) { - $node->flags |= Class_::MODIFIER_PUBLIC; - $node->flags -= Class_::MODIFIER_PUBLIC; - } - - if ($node->isProtected()) { - $node->flags -= Class_::MODIFIER_PROTECTED; - } - - if ($node->isPrivate()) { - $node->flags -= Class_::MODIFIER_PRIVATE; - } - } - public function changeNodeVisibility(ClassMethod | Property | ClassConst $node, int $visibility): void { Assert::oneOf($visibility, [ @@ -137,6 +108,9 @@ public function removeFinal(Class_ | ClassConst $node): void $node->flags -= Class_::MODIFIER_FINAL; } + /** + * @api downgrade + */ public function removeAbstract(ClassMethod $classMethod): void { $classMethod->flags -= Class_::MODIFIER_ABSTRACT; @@ -157,6 +131,30 @@ public function removeReadonly(Class_ | Property | Param $node): void $this->removeVisibilityFlag($node, Visibility::READONLY); } + /** + * This way "abstract", "static", "final" are kept + */ + private function removeVisibility(ClassMethod | Property | ClassConst $node): void + { + // no modifier + if ($node->flags === 0) { + return; + } + + if ($node->isPublic()) { + $node->flags |= Class_::MODIFIER_PUBLIC; + $node->flags -= Class_::MODIFIER_PUBLIC; + } + + if ($node->isProtected()) { + $node->flags -= Class_::MODIFIER_PROTECTED; + } + + if ($node->isPrivate()) { + $node->flags -= Class_::MODIFIER_PRIVATE; + } + } + /** * @api */ diff --git a/rules/Renaming/Collector/MethodCallRenameCollector.php b/rules/Renaming/Collector/MethodCallRenameCollector.php deleted file mode 100644 index aab281f6711..00000000000 --- a/rules/Renaming/Collector/MethodCallRenameCollector.php +++ /dev/null @@ -1,31 +0,0 @@ -methodCallRenames = array_merge($this->methodCallRenames, $methodCallRenames); - } - - /** - * @return MethodCallRenameInterface[] - */ - public function getMethodCallRenames(): array - { - return $this->methodCallRenames; - } -} diff --git a/rules/Renaming/Helper/RenameClassCallbackHandler.php b/rules/Renaming/Helper/RenameClassCallbackHandler.php index 5ee61fcf8ed..af6d8cc8e93 100644 --- a/rules/Renaming/Helper/RenameClassCallbackHandler.php +++ b/rules/Renaming/Helper/RenameClassCallbackHandler.php @@ -54,7 +54,7 @@ public function getOldToNewClassesFromNode(Node $node): array /** * @return array */ - public function handleClassLike(ClassLike $classLike): array + private function handleClassLike(ClassLike $classLike): array { $oldToNewClasses = []; $className = $classLike->name; diff --git a/rules/Renaming/Rector/MethodCall/RenameMethodRector.php b/rules/Renaming/Rector/MethodCall/RenameMethodRector.php index 9f533636753..586149e80cb 100644 --- a/rules/Renaming/Rector/MethodCall/RenameMethodRector.php +++ b/rules/Renaming/Rector/MethodCall/RenameMethodRector.php @@ -19,7 +19,6 @@ use Rector\Core\NodeManipulator\ClassManipulator; use Rector\Core\Rector\AbstractScopeAwareRector; use Rector\Core\Reflection\ReflectionResolver; -use Rector\Renaming\Collector\MethodCallRenameCollector; use Rector\Renaming\Contract\MethodCallRenameInterface; use Rector\Renaming\ValueObject\MethodCallRename; use Rector\Renaming\ValueObject\MethodCallRenameWithArrayKey; @@ -39,7 +38,6 @@ final class RenameMethodRector extends AbstractScopeAwareRector implements Confi public function __construct( private readonly ClassManipulator $classManipulator, - private readonly MethodCallRenameCollector $methodCallRenameCollector, private readonly ReflectionResolver $reflectionResolver, private readonly ReflectionProvider $reflectionProvider ) { @@ -119,7 +117,6 @@ public function configure(array $configuration): void Assert::allIsAOf($configuration, MethodCallRenameInterface::class); $this->methodCallRenames = $configuration; - $this->methodCallRenameCollector->addMethodCallRenames($configuration); } private function shouldSkipClassMethod( diff --git a/rules/Transform/Rector/New_/NewArgToMethodCallRector.php b/rules/Transform/Rector/New_/NewArgToMethodCallRector.php index a104c3722d5..9cfe7070093 100644 --- a/rules/Transform/Rector/New_/NewArgToMethodCallRector.php +++ b/rules/Transform/Rector/New_/NewArgToMethodCallRector.php @@ -90,7 +90,7 @@ public function refactor(Node $node): ?Node unset($node->args[0]); - return new MethodCall($node, 'usePutenv'); + return new MethodCall($node, $newArgToMethodCall->getMethodCall()); } return null; diff --git a/rules/TypeDeclaration/Guard/PhpDocNestedAnnotationGuard.php b/rules/TypeDeclaration/Guard/PhpDocNestedAnnotationGuard.php index 809e8baf57c..6a8ff7638f2 100755 --- a/rules/TypeDeclaration/Guard/PhpDocNestedAnnotationGuard.php +++ b/rules/TypeDeclaration/Guard/PhpDocNestedAnnotationGuard.php @@ -50,7 +50,7 @@ public function isPhpDocCommentCorrectlyParsed(Node $node): bool return ! $this->hasAnnotationCountChanged($originalPhpDocText, $parsedPhpDocText); } - public function hasAnnotationCountChanged(string $originalPhpDocText, string $updatedPhpDocText): bool + private function hasAnnotationCountChanged(string $originalPhpDocText, string $updatedPhpDocText): bool { $originalAnnotationCount = count(Strings::matchAll($originalPhpDocText, self::SIMPLE_ANNOTATION_REGEX)); $reconstructedAnnotationCount = count(Strings::matchAll($updatedPhpDocText, self::SIMPLE_ANNOTATION_REGEX)); diff --git a/rules/TypeDeclaration/NodeAnalyzer/CallerParamMatcher.php b/rules/TypeDeclaration/NodeAnalyzer/CallerParamMatcher.php index c4f579c37eb..035bfc3fc1e 100644 --- a/rules/TypeDeclaration/NodeAnalyzer/CallerParamMatcher.php +++ b/rules/TypeDeclaration/NodeAnalyzer/CallerParamMatcher.php @@ -42,35 +42,35 @@ public function matchCallParamType( return $callParam->type; } - public function matchCallParam(StaticCall | MethodCall | FuncCall $call, Param $param, Scope $scope): ?Param + public function matchParentParam(StaticCall $parentStaticCall, Param $param, Scope $scope): ?Param { - $callArgPosition = $this->matchCallArgPosition($call, $param); - if ($callArgPosition === null) { + $methodName = $this->nodeNameResolver->getName($parentStaticCall->name); + if ($methodName === null) { return null; } - $classMethodOrFunction = $this->astResolver->resolveClassMethodOrFunctionFromCall($call, $scope); - if ($classMethodOrFunction === null) { + // match current param to parent call position + $parentStaticCallArgPosition = $this->matchCallArgPosition($parentStaticCall, $param); + if ($parentStaticCallArgPosition === null) { return null; } - return $classMethodOrFunction->params[$callArgPosition] ?? null; + return $this->resolveParentMethodParam($scope, $methodName, $parentStaticCallArgPosition); } - public function matchParentParam(StaticCall $parentStaticCall, Param $param, Scope $scope): ?Param + private function matchCallParam(StaticCall | MethodCall | FuncCall $call, Param $param, Scope $scope): ?Param { - $methodName = $this->nodeNameResolver->getName($parentStaticCall->name); - if ($methodName === null) { + $callArgPosition = $this->matchCallArgPosition($call, $param); + if ($callArgPosition === null) { return null; } - // match current param to parent call position - $parentStaticCallArgPosition = $this->matchCallArgPosition($parentStaticCall, $param); - if ($parentStaticCallArgPosition === null) { + $classMethodOrFunction = $this->astResolver->resolveClassMethodOrFunctionFromCall($call, $scope); + if ($classMethodOrFunction === null) { return null; } - return $this->resolveParentMethodParam($scope, $methodName, $parentStaticCallArgPosition); + return $classMethodOrFunction->params[$callArgPosition] ?? null; } private function matchCallArgPosition(StaticCall | MethodCall | FuncCall $call, Param $param): int | null diff --git a/rules/TypeDeclaration/NodeAnalyzer/ReturnTypeAnalyzer/StrictReturnNewAnalyzer.php b/rules/TypeDeclaration/NodeAnalyzer/ReturnTypeAnalyzer/StrictReturnNewAnalyzer.php index 1b5e3197ae6..e0b3f5768b5 100644 --- a/rules/TypeDeclaration/NodeAnalyzer/ReturnTypeAnalyzer/StrictReturnNewAnalyzer.php +++ b/rules/TypeDeclaration/NodeAnalyzer/ReturnTypeAnalyzer/StrictReturnNewAnalyzer.php @@ -148,6 +148,6 @@ private function matchAssignToVariable(Stmt $stmt): ?AssignToVariable return null; } - return new AssignToVariable($assignedVar, $variableName, $assign->expr); + return new AssignToVariable($variableName, $assign->expr); } } diff --git a/rules/TypeDeclaration/Rector/Param/ParamTypeFromStrictTypedPropertyRector.php b/rules/TypeDeclaration/Rector/Param/ParamTypeFromStrictTypedPropertyRector.php index 36b43a9a9d1..4b02c30e459 100644 --- a/rules/TypeDeclaration/Rector/Param/ParamTypeFromStrictTypedPropertyRector.php +++ b/rules/TypeDeclaration/Rector/Param/ParamTypeFromStrictTypedPropertyRector.php @@ -92,7 +92,12 @@ public function refactor(Node $node): ?Node return $this->decorateParamWithType($parentNode, $node); } - public function decorateParamWithType(ClassMethod $classMethod, Param $param): ?Param + public function provideMinPhpVersion(): int + { + return PhpVersionFeature::TYPED_PROPERTIES; + } + + private function decorateParamWithType(ClassMethod $classMethod, Param $param): ?Param { if ($param->type !== null) { return null; @@ -133,11 +138,6 @@ public function decorateParamWithType(ClassMethod $classMethod, Param $param): ? return null; } - public function provideMinPhpVersion(): int - { - return PhpVersionFeature::TYPED_PROPERTIES; - } - /** * @return Identifier|Name|ComplexType|null */ diff --git a/rules/TypeDeclaration/Rector/Property/TypedPropertyFromStrictGetterMethodReturnTypeRector.php b/rules/TypeDeclaration/Rector/Property/TypedPropertyFromStrictGetterMethodReturnTypeRector.php index d2692b31be8..307cd4c78c5 100644 --- a/rules/TypeDeclaration/Rector/Property/TypedPropertyFromStrictGetterMethodReturnTypeRector.php +++ b/rules/TypeDeclaration/Rector/Property/TypedPropertyFromStrictGetterMethodReturnTypeRector.php @@ -18,13 +18,14 @@ use Rector\PHPStanStaticTypeMapper\Enum\TypeKind; use Rector\Privatization\Guard\ParentPropertyLookupGuard; use Rector\TypeDeclaration\TypeInferer\PropertyTypeInferer\GetterTypeDeclarationPropertyTypeInferer; +use Rector\VersionBonding\Contract\MinPhpVersionInterface; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * @see \Rector\Tests\TypeDeclaration\Rector\Property\TypedPropertyFromStrictGetterMethodReturnTypeRector\TypedPropertyFromStrictGetterMethodReturnTypeRectorTest */ -final class TypedPropertyFromStrictGetterMethodReturnTypeRector extends AbstractRector +final class TypedPropertyFromStrictGetterMethodReturnTypeRector extends AbstractRector implements MinPhpVersionInterface { public function __construct( private readonly GetterTypeDeclarationPropertyTypeInferer $getterTypeDeclarationPropertyTypeInferer, diff --git a/rules/TypeDeclaration/TypeInferer/ReturnTypeInferer.php b/rules/TypeDeclaration/TypeInferer/ReturnTypeInferer.php index 5a1344489ce..4ee3ee3e286 100644 --- a/rules/TypeDeclaration/TypeInferer/ReturnTypeInferer.php +++ b/rules/TypeDeclaration/TypeInferer/ReturnTypeInferer.php @@ -78,16 +78,13 @@ public function inferFunctionLike(ClassMethod|Function_|Closure|ArrowFunction $f } $type = $this->verifyThisType($type, $functionLike); - if (! $type instanceof Type) { - return new MixedType(); - } // normalize ConstStringType to ClassStringType $resolvedType = $this->genericClassStringTypeNormalizer->normalize($type); return $this->resolveTypeWithVoidHandling($functionLike, $resolvedType); } - public function verifyStaticType(Type $type, bool $isSupportedStaticReturnType): ?Type + private function verifyStaticType(Type $type, bool $isSupportedStaticReturnType): ?Type { if ($this->isStaticType($type)) { /** @var TypeWithClassName $type */ @@ -101,7 +98,7 @@ public function verifyStaticType(Type $type, bool $isSupportedStaticReturnType): return $type; } - public function verifyThisType(Type $type, FunctionLike $functionLike): ?Type + private function verifyThisType(Type $type, FunctionLike $functionLike): Type { if (! $type instanceof ThisType) { return $type; diff --git a/rules/TypeDeclaration/TypeNormalizer.php b/rules/TypeDeclaration/TypeNormalizer.php index 952d8934372..54395590c3f 100644 --- a/rules/TypeDeclaration/TypeNormalizer.php +++ b/rules/TypeDeclaration/TypeNormalizer.php @@ -6,11 +6,8 @@ use PHPStan\Type\ArrayType; use PHPStan\Type\Constant\ConstantArrayType; -use PHPStan\Type\Constant\ConstantStringType; use PHPStan\Type\MixedType; use PHPStan\Type\NeverType; -use PHPStan\Type\ObjectType; -use PHPStan\Type\StringType; use PHPStan\Type\Type; use PHPStan\Type\TypeTraverser; use PHPStan\Type\UnionType; @@ -34,30 +31,6 @@ public function __construct( ) { } - public function convertConstantArrayTypeToArrayType(ConstantArrayType $constantArrayType): ?ArrayType - { - $nonConstantValueTypes = []; - - if ($constantArrayType->getItemType() instanceof UnionType) { - /** @var UnionType $unionType */ - $unionType = $constantArrayType->getItemType(); - foreach ($unionType->getTypes() as $unionedType) { - if ($unionedType instanceof ConstantStringType) { - $stringType = new StringType(); - $nonConstantValueTypes[$stringType::class] = $stringType; - } elseif ($unionedType instanceof ObjectType) { - $nonConstantValueTypes[] = $unionedType; - } else { - return null; - } - } - } else { - return null; - } - - return $this->createArrayTypeFromNonConstantValueTypes($nonConstantValueTypes); - } - /** * @api * @@ -182,21 +155,6 @@ private function isUnionMixedArrayNeverType(int $countTraversedTypes, array $tra ) || $this->isArrayNeverType($traversedTypeTypes[1])); } - /** - * @param array $nonConstantValueTypes - */ - private function createArrayTypeFromNonConstantValueTypes(array $nonConstantValueTypes): ArrayType - { - $nonConstantValueTypes = array_values($nonConstantValueTypes); - if (count($nonConstantValueTypes) > 1) { - $nonConstantValueType = new UnionType($nonConstantValueTypes); - } else { - $nonConstantValueType = $nonConstantValueTypes[0]; - } - - return new ArrayType(new MixedType(), $nonConstantValueType); - } - private function collectNestedArrayTypeFromUnionType(UnionType $unionType, int $arrayNesting): void { foreach ($unionType->getTypes() as $unionedType) { diff --git a/rules/TypeDeclaration/ValueObject/AddReturnTypeDeclaration.php b/rules/TypeDeclaration/ValueObject/AddReturnTypeDeclaration.php index 47125ec82af..d929d44b8ad 100644 --- a/rules/TypeDeclaration/ValueObject/AddReturnTypeDeclaration.php +++ b/rules/TypeDeclaration/ValueObject/AddReturnTypeDeclaration.php @@ -8,6 +8,9 @@ use PHPStan\Type\Type; use Rector\Core\Validation\RectorAssert; +/** + * @api + */ final class AddReturnTypeDeclaration { public function __construct( diff --git a/rules/TypeDeclaration/ValueObject/AssignToVariable.php b/rules/TypeDeclaration/ValueObject/AssignToVariable.php index 4e2482413b7..13a2c209b8f 100644 --- a/rules/TypeDeclaration/ValueObject/AssignToVariable.php +++ b/rules/TypeDeclaration/ValueObject/AssignToVariable.php @@ -5,22 +5,15 @@ namespace Rector\TypeDeclaration\ValueObject; use PhpParser\Node\Expr; -use PhpParser\Node\Expr\Variable; final class AssignToVariable { public function __construct( - private readonly Variable $variable, private readonly string $variableName, private readonly Expr $assignedExpr ) { } - public function getVariable(): Variable - { - return $this->variable; - } - public function getVariableName(): string { return $this->variableName; diff --git a/src/Application/ApplicationFileProcessor.php b/src/Application/ApplicationFileProcessor.php index 64ffc09d927..7999ea8e03a 100644 --- a/src/Application/ApplicationFileProcessor.php +++ b/src/Application/ApplicationFileProcessor.php @@ -99,7 +99,7 @@ public function run(Configuration $configuration, InputInterface $input): array } /** - * @internal Use only for tests + * @api use only for tests * * @param File[] $files * @return array{system_errors: SystemError[], file_diffs: FileDiff[]} diff --git a/src/Application/FileSystem/RemovedAndAddedFilesCollector.php b/src/Application/FileSystem/RemovedAndAddedFilesCollector.php index 90e6c98bc62..a53ffb462ef 100644 --- a/src/Application/FileSystem/RemovedAndAddedFilesCollector.php +++ b/src/Application/FileSystem/RemovedAndAddedFilesCollector.php @@ -106,7 +106,7 @@ public function getRemovedFilesCount(): int } /** - * For testing + * @api For testing */ public function reset(): void { diff --git a/src/Application/VersionResolver.php b/src/Application/VersionResolver.php index c2edaf0a8da..82f20861bfb 100644 --- a/src/Application/VersionResolver.php +++ b/src/Application/VersionResolver.php @@ -8,6 +8,8 @@ use Rector\Core\Exception\VersionException; /** + * @api + * * Inspired by https://github.com/composer/composer/blob/master/src/Composer/Composer.php * See https://github.com/composer/composer/blob/6587715d0f8cae0cd39073b3bc5f018d0e6b84fe/src/Composer/Compiler.php#L208 * diff --git a/src/Bootstrap/ExtensionConfigResolver.php b/src/Bootstrap/ExtensionConfigResolver.php index 4aba5769d08..bfaeba3cf65 100644 --- a/src/Bootstrap/ExtensionConfigResolver.php +++ b/src/Bootstrap/ExtensionConfigResolver.php @@ -10,6 +10,7 @@ final class ExtensionConfigResolver { /** + * @api * @return string[] */ public function provide(): array diff --git a/src/Configuration/ConfigurationFactory.php b/src/Configuration/ConfigurationFactory.php index f4d45bab584..fc8197feca6 100644 --- a/src/Configuration/ConfigurationFactory.php +++ b/src/Configuration/ConfigurationFactory.php @@ -19,6 +19,7 @@ public function __construct( } /** + * @api used in tests * @param string[] $paths */ public function createForTests(array $paths): Configuration diff --git a/src/Configuration/RectorConfigProvider.php b/src/Configuration/RectorConfigProvider.php index 71863c12544..bbf160a7638 100644 --- a/src/Configuration/RectorConfigProvider.php +++ b/src/Configuration/RectorConfigProvider.php @@ -22,11 +22,17 @@ public function shouldImportNames(): bool return $this->parameterProvider->provideBoolParameter(Option::AUTO_IMPORT_NAMES); } + /** + * @api symfony + */ public function getSymfonyContainerPhp(): string { return $this->parameterProvider->provideStringParameter(Option::SYMFONY_CONTAINER_PHP_PATH_PARAMETER); } + /** + * @api symfony + */ public function getSymfonyContainerXml(): string { return $this->parameterProvider->provideStringParameter(Option::SYMFONY_CONTAINER_XML_PATH_PARAMETER); diff --git a/src/Configuration/ValueObjectInliner.php b/src/Configuration/ValueObjectInliner.php index 5010400c9db..a6a8c9ee3b5 100644 --- a/src/Configuration/ValueObjectInliner.php +++ b/src/Configuration/ValueObjectInliner.php @@ -28,7 +28,7 @@ public static function inline(object | array $object): InlineServiceConfigurator * @param ReflectionClass $reflectionClass * @return mixed[] */ - public static function resolveArgumentValues(ReflectionClass $reflectionClass, object $object): array + private static function resolveArgumentValues(ReflectionClass $reflectionClass, object $object): array { $argumentValues = []; diff --git a/src/Console/Output/OutputFormatterCollector.php b/src/Console/Output/OutputFormatterCollector.php index de7accf9aff..3f0387594f4 100644 --- a/src/Console/Output/OutputFormatterCollector.php +++ b/src/Console/Output/OutputFormatterCollector.php @@ -31,24 +31,18 @@ public function getByName(string $name): OutputFormatterInterface return $this->outputFormatters[$name]; } - /** - * @return string[] - */ - public function getNames(): array - { - return array_keys($this->outputFormatters); - } - private function ensureOutputFormatExists(string $name): void { if (isset($this->outputFormatters[$name])) { return; } + $outputFormatterNames = array_keys($this->outputFormatters); + throw new InvalidConfigurationException(sprintf( 'Output formatter "%s" was not found. Pick one of "%s".', $name, - implode('", "', $this->getNames()) + implode('", "', $outputFormatterNames) )); } } diff --git a/src/Error/ExceptionCorrector.php b/src/Error/ExceptionCorrector.php index 6b2ac877fa1..b148bfd59f7 100644 --- a/src/Error/ExceptionCorrector.php +++ b/src/Error/ExceptionCorrector.php @@ -5,30 +5,9 @@ namespace Rector\Core\Error; use PHPStan\AnalysedCodeException; -use Rector\Core\Contract\Rector\RectorInterface; -use Throwable; final class ExceptionCorrector { - public function matchRectorClass(Throwable $throwable): ?string - { - if (! isset($throwable->getTrace()[0])) { - return null; - } - - if (! isset($throwable->getTrace()[0]['class'])) { - return null; - } - - /** @var string $class */ - $class = $throwable->getTrace()[0]['class']; - if (! is_a($class, RectorInterface::class, true)) { - return null; - } - - return $class; - } - public function getAutoloadExceptionMessageAndAddLocation(AnalysedCodeException $analysedCodeException): string { return sprintf( diff --git a/src/Kernel/RectorKernel.php b/src/Kernel/RectorKernel.php index 9716088b140..0733d7f311c 100644 --- a/src/Kernel/RectorKernel.php +++ b/src/Kernel/RectorKernel.php @@ -59,6 +59,9 @@ public function createFromConfigs(array $configFiles): ContainerBuilder return $containerBuilder; } + /** + * @api used in tests + */ public function getContainer(): ContainerInterface { if ($this->container === null) { diff --git a/src/NodeAnalyzer/CoalesceAnalyzer.php b/src/NodeAnalyzer/CoalesceAnalyzer.php index 1fa0695fbc4..dc2240c2a7c 100644 --- a/src/NodeAnalyzer/CoalesceAnalyzer.php +++ b/src/NodeAnalyzer/CoalesceAnalyzer.php @@ -23,6 +23,9 @@ final class CoalesceAnalyzer StaticPropertyFetch::class, ]; + /** + * @api downgrade + */ public function hasIssetableLeft(Coalesce $coalesce): bool { $leftClass = $coalesce->left::class; diff --git a/src/NodeDecorator/NamespacedNameDecorator.php b/src/NodeDecorator/NamespacedNameDecorator.php index 01eeea610a4..ac35c5fd36d 100644 --- a/src/NodeDecorator/NamespacedNameDecorator.php +++ b/src/NodeDecorator/NamespacedNameDecorator.php @@ -11,6 +11,7 @@ final class NamespacedNameDecorator { /** + * @api downgrade * @param Node|Node[] $node */ public function decorate(Node|array $node): void diff --git a/src/NodeManipulator/ArrayManipulator.php b/src/NodeManipulator/ArrayManipulator.php index 1bc6e8735da..1bb1f706cc5 100644 --- a/src/NodeManipulator/ArrayManipulator.php +++ b/src/NodeManipulator/ArrayManipulator.php @@ -47,6 +47,9 @@ public function isDynamicArray(Array_ $array): bool return false; } + /** + * @api symfony + */ public function addItemToArrayUnderKey(Array_ $array, ArrayItem $newArrayItem, string $key): void { foreach ($array->items as $item) { @@ -67,6 +70,9 @@ public function addItemToArrayUnderKey(Array_ $array, ArrayItem $newArrayItem, s $array->items[] = new ArrayItem(new Array_([$newArrayItem]), new String_($key)); } + /** + * @api + */ public function findItemInInArrayByKeyAndUnset(Array_ $array, string $keyName): ?ArrayItem { foreach ($array->items as $i => $item) { @@ -94,6 +100,9 @@ public function findItemInInArrayByKeyAndUnset(Array_ $array, string $keyName): return null; } + /** + * @api symfony + */ public function hasKeyName(ArrayItem $arrayItem, string $name): bool { if (! $arrayItem->key instanceof String_) { diff --git a/src/NodeManipulator/AssignManipulator.php b/src/NodeManipulator/AssignManipulator.php index 29fc45ce8fa..eea8ec28025 100644 --- a/src/NodeManipulator/AssignManipulator.php +++ b/src/NodeManipulator/AssignManipulator.php @@ -122,6 +122,7 @@ public function isNodePartOfAssign(Node $node): bool } /** + * @api doctrine * @return array */ public function resolveAssignsToLocalPropertyFetches(FunctionLike $functionLike): array diff --git a/src/NodeManipulator/ClassDependencyManipulator.php b/src/NodeManipulator/ClassDependencyManipulator.php index 8a2f7e17bc0..ca2d5989f23 100644 --- a/src/NodeManipulator/ClassDependencyManipulator.php +++ b/src/NodeManipulator/ClassDependencyManipulator.php @@ -74,6 +74,9 @@ public function addConstructorDependency(Class_ $class, PropertyMetadata $proper } } + /** + * @api doctrine + */ public function addConstructorDependencyWithCustomAssign( Class_ $class, string $name, @@ -109,6 +112,7 @@ public function addConstructorDependencyWithCustomAssign( } /** + * @api doctrine * @param Stmt[] $stmts */ public function addStmtsToConstructorIfNotThereYet(Class_ $class, array $stmts): void diff --git a/src/NodeManipulator/ClassInsertManipulator.php b/src/NodeManipulator/ClassInsertManipulator.php index 54f72eba46d..62a2e869fe3 100644 --- a/src/NodeManipulator/ClassInsertManipulator.php +++ b/src/NodeManipulator/ClassInsertManipulator.php @@ -55,6 +55,7 @@ public function addConstantToClass(Class_ $class, string $constantName, ClassCon } /** + * @api * @param Property[] $properties */ public function addPropertiesToClass(Class_ $class, array $properties): void diff --git a/src/NodeManipulator/ClassManipulator.php b/src/NodeManipulator/ClassManipulator.php index 46a0aa1c963..592c56df9d8 100644 --- a/src/NodeManipulator/ClassManipulator.php +++ b/src/NodeManipulator/ClassManipulator.php @@ -4,7 +4,6 @@ namespace Rector\Core\NodeManipulator; -use PhpParser\Node\Name\FullyQualified; use PhpParser\Node\Stmt\Class_; use PHPStan\Reflection\ReflectionProvider; use PHPStan\Type\ObjectType; @@ -43,6 +42,9 @@ public function hasParentMethodOrInterface(ObjectType $objectType, string $oldMe return false; } + /** + * @api phpunit + */ public function hasTrait(Class_ $class, string $desiredTrait): bool { foreach ($class->getTraitUses() as $traitUse) { @@ -57,18 +59,4 @@ public function hasTrait(Class_ $class, string $desiredTrait): bool return false; } - - public function replaceTrait(Class_ $class, string $oldTrait, string $newTrait): void - { - foreach ($class->getTraitUses() as $traitUse) { - foreach ($traitUse->traits as $key => $traitTrait) { - if (! $this->nodeNameResolver->isName($traitTrait, $oldTrait)) { - continue; - } - - $traitUse->traits[$key] = new FullyQualified($newTrait); - break; - } - } - } } diff --git a/src/NodeManipulator/ClassMethodManipulator.php b/src/NodeManipulator/ClassMethodManipulator.php index 0ad89a4b09f..3c27384ec0d 100644 --- a/src/NodeManipulator/ClassMethodManipulator.php +++ b/src/NodeManipulator/ClassMethodManipulator.php @@ -4,27 +4,19 @@ namespace Rector\Core\NodeManipulator; -use PhpParser\Node; -use PhpParser\Node\Expr\Variable; -use PhpParser\Node\Name\FullyQualified; -use PhpParser\Node\Param; use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\ClassMethod; use PHPStan\Reflection\ClassReflection; -use PHPStan\Type\ObjectType; -use Rector\Core\Exception\ShouldNotHappenException; use Rector\Core\PhpParser\Node\BetterNodeFinder; use Rector\Core\Reflection\ReflectionResolver; use Rector\Core\ValueObject\MethodName; use Rector\NodeNameResolver\NodeNameResolver; -use Rector\NodeTypeResolver\NodeTypeResolver; final class ClassMethodManipulator { public function __construct( private readonly BetterNodeFinder $betterNodeFinder, private readonly NodeNameResolver $nodeNameResolver, - private readonly NodeTypeResolver $nodeTypeResolver, private readonly ReflectionResolver $reflectionResolver ) { } @@ -77,49 +69,4 @@ public function hasParentMethodOrInterfaceMethod(ClassMethod $classMethod, ?stri return false; } - - /** - * @param string[] $possibleNames - */ - public function addMethodParameterIfMissing(Node $node, ObjectType $objectType, array $possibleNames): string - { - $classMethod = $this->betterNodeFinder->findParentType($node, ClassMethod::class); - if (! $classMethod instanceof ClassMethod) { - // or null? - throw new ShouldNotHappenException(); - } - - foreach ($classMethod->params as $paramNode) { - if (! $this->nodeTypeResolver->isObjectType($paramNode, $objectType)) { - continue; - } - - return $this->nodeNameResolver->getName($paramNode); - } - - $paramName = $this->resolveName($classMethod, $possibleNames); - $classMethod->params[] = new Param(new Variable($paramName), null, new FullyQualified( - $objectType->getClassName() - )); - - return $paramName; - } - - /** - * @param string[] $possibleNames - */ - private function resolveName(ClassMethod $classMethod, array $possibleNames): string - { - foreach ($possibleNames as $possibleName) { - foreach ($classMethod->params as $paramNode) { - if ($this->nodeNameResolver->isName($paramNode, $possibleName)) { - continue 2; - } - } - - return $possibleName; - } - - throw new ShouldNotHappenException(); - } } diff --git a/src/NodeManipulator/IfManipulator.php b/src/NodeManipulator/IfManipulator.php index febd87cd827..3e881db4c9c 100644 --- a/src/NodeManipulator/IfManipulator.php +++ b/src/NodeManipulator/IfManipulator.php @@ -10,7 +10,6 @@ use PhpParser\Node\Expr\BinaryOp\Identical; use PhpParser\Node\Expr\BinaryOp\NotIdentical; use PhpParser\Node\Expr\Exit_; -use PhpParser\Node\Expr\FuncCall; use PhpParser\Node\Expr\Variable; use PhpParser\Node\Stmt; use PhpParser\Node\Stmt\Foreach_; @@ -20,13 +19,11 @@ use Rector\Core\PhpParser\Node\BetterNodeFinder; use Rector\Core\PhpParser\Node\Value\ValueResolver; use Rector\EarlyReturn\NodeTransformer\ConditionInverter; -use Rector\NodeNameResolver\NodeNameResolver; final class IfManipulator { public function __construct( private readonly BetterNodeFinder $betterNodeFinder, - private readonly NodeNameResolver $nodeNameResolver, private readonly StmtsManipulator $stmtsManipulator, private readonly ValueResolver $valueResolver, private readonly ConditionInverter $conditionInverter, @@ -156,25 +153,6 @@ public function isIfAndElseWithSameVariableAssignAsLastStmts(If_ $if, Expr $desi return $this->nodeComparator->areNodesEqual($desiredExpr, $lastElseStmt->var); } - /** - * Matches: - * if () { - * } else { - * } - */ - public function isIfOrIfElseWithFunctionCondition(If_ $if, string $functionName): bool - { - if ((bool) $if->elseifs) { - return false; - } - - if (! $if->cond instanceof FuncCall) { - return false; - } - - return $this->nodeNameResolver->isName($if->cond, $functionName); - } - /** * @return If_[] */ diff --git a/src/NodeManipulator/MethodCallManipulator.php b/src/NodeManipulator/MethodCallManipulator.php index 72528cd4701..df50948bcae 100644 --- a/src/NodeManipulator/MethodCallManipulator.php +++ b/src/NodeManipulator/MethodCallManipulator.php @@ -22,6 +22,7 @@ public function __construct( } /** + * @api * @return string[] */ public function findMethodCallNamesOnVariable(Variable $variable): array @@ -44,7 +45,7 @@ public function findMethodCallNamesOnVariable(Variable $variable): array /** * @return MethodCall[] */ - public function findMethodCallsOnVariable(Variable $variable): array + private function findMethodCallsOnVariable(Variable $variable): array { // get scope node, e.g. parent function call, method call or anonymous function $classMethod = $this->betterNodeFinder->findParentType($variable, ClassMethod::class); diff --git a/src/NodeManipulator/PropertyManipulator.php b/src/NodeManipulator/PropertyManipulator.php index 9d006ef3346..31406714d93 100644 --- a/src/NodeManipulator/PropertyManipulator.php +++ b/src/NodeManipulator/PropertyManipulator.php @@ -94,18 +94,6 @@ public function __construct( ) { } - public function isAllowedReadOnly(Property | Param $propertyOrPromotedParam, PhpDocInfo $phpDocInfo): bool - { - if ($phpDocInfo->hasByAnnotationClasses(self::ALLOWED_READONLY_ANNOTATION_CLASS_OR_ATTRIBUTES)) { - return true; - } - - return $this->phpAttributeAnalyzer->hasPhpAttributes( - $propertyOrPromotedParam, - self::ALLOWED_READONLY_ANNOTATION_CLASS_OR_ATTRIBUTES - ); - } - public function isPropertyUsedInReadContext(Class_ $class, Property | Param $propertyOrPromotedParam): bool { $phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($propertyOrPromotedParam); @@ -250,6 +238,18 @@ public function isUsedByTrait(ClassReflection $classReflection, string $property return false; } + private function isAllowedReadOnly(Property | Param $propertyOrPromotedParam, PhpDocInfo $phpDocInfo): bool + { + if ($phpDocInfo->hasByAnnotationClasses(self::ALLOWED_READONLY_ANNOTATION_CLASS_OR_ATTRIBUTES)) { + return true; + } + + return $this->phpAttributeAnalyzer->hasPhpAttributes( + $propertyOrPromotedParam, + self::ALLOWED_READONLY_ANNOTATION_CLASS_OR_ATTRIBUTES + ); + } + private function isPropertyAssignedOnlyInConstructor( Class_ $class, string $propertyName, diff --git a/src/Php/ReservedKeywordAnalyzer.php b/src/Php/ReservedKeywordAnalyzer.php index f343754adfc..cd1067d4a9d 100644 --- a/src/Php/ReservedKeywordAnalyzer.php +++ b/src/Php/ReservedKeywordAnalyzer.php @@ -6,84 +6,6 @@ final class ReservedKeywordAnalyzer { - /** - * @see https://www.php.net/manual/en/reserved.keywords.php - * @var string[] - */ - private const RESERVED_KEYWORDS = [ - '__halt_compiler', - 'abstract', - 'and', - 'array', - 'as', - 'break', - 'callable', - 'case', - 'catch', - 'class', - 'clone', - 'const', - 'continue', - 'declare', - 'default', - 'die', - 'do', - 'echo', - 'else', - 'elseif', - 'empty', - 'enddeclare', - 'endfor', - 'endforeach', - 'endif', - 'endswitch', - 'endwhile', - 'eval', - 'exit', - 'extends', - 'final', - 'finally', - 'fn', - 'for', - 'foreach', - 'function', - 'global', - 'goto', - 'if', - 'implements', - 'include', - 'include_once', - 'instanceof', - 'insteadof', - 'interface', - 'isset', - 'list', - 'match', - 'namespace', - 'new', - 'or', - 'print', - 'private', - 'protected', - 'public', - 'readonly', - 'require', - 'require_once', - 'return', - 'static', - 'switch', - 'throw', - 'trait', - 'try', - 'unset', - 'use', - 'var', - 'while', - 'xor', - 'yield', - 'yield from', - ]; - /** * @var string[] */ @@ -103,10 +25,4 @@ public function isNativeVariable(string $name): bool { return in_array($name, self::NATIVE_VARIABLE_NAMES, true); } - - public function isReserved(string $keyword): bool - { - $keyword = strtolower($keyword); - return in_array($keyword, self::RESERVED_KEYWORDS, true); - } } diff --git a/src/PhpParser/AstResolver.php b/src/PhpParser/AstResolver.php index 34adcec64f9..7ec18d2aa94 100644 --- a/src/PhpParser/AstResolver.php +++ b/src/PhpParser/AstResolver.php @@ -80,12 +80,6 @@ public function resolveClassFromName(string $className): Class_ | Trait_ | Inter return $this->resolveClassFromClassReflection($classReflection); } - public function resolveClassFromObjectType( - TypeWithClassName $typeWithClassName - ): Class_ | Trait_ | Interface_ | Enum_ | null { - return $this->resolveClassFromName($typeWithClassName->getClassName()); - } - public function resolveClassMethodFromMethodReflection(MethodReflection $methodReflection): ?ClassMethod { $classReflection = $methodReflection->getDeclaringClass(); diff --git a/src/PhpParser/Node/BetterNodeFinder.php b/src/PhpParser/Node/BetterNodeFinder.php index 4959a4c8fbb..662fa50b75c 100644 --- a/src/PhpParser/Node/BetterNodeFinder.php +++ b/src/PhpParser/Node/BetterNodeFinder.php @@ -213,6 +213,7 @@ public function find(Node | array $nodes, callable $filter): array } /** + * @api symfony * @param Node[] $nodes * @return ClassLike|null */ @@ -262,6 +263,7 @@ public function findClassMethodAssignsToLocalProperty(ClassMethod $classMethod, } /** + * @api symfony * @return Assign|null */ public function findPreviousAssignToExpr(Expr $expr): ?Node diff --git a/src/PhpParser/Node/NamedVariableFactory.php b/src/PhpParser/Node/NamedVariableFactory.php index 24e8f4b5164..86400fd4fde 100644 --- a/src/PhpParser/Node/NamedVariableFactory.php +++ b/src/PhpParser/Node/NamedVariableFactory.php @@ -18,6 +18,9 @@ public function __construct( ) { } + /** + * @api downgrade + */ public function createVariable(Node $node, string $variableName): Variable { $currentStmt = $this->betterNodeFinder->resolveCurrentStatement($node); diff --git a/src/PhpParser/Node/NodeFactory.php b/src/PhpParser/Node/NodeFactory.php index 14a0a1c559e..93f39bad203 100644 --- a/src/PhpParser/Node/NodeFactory.php +++ b/src/PhpParser/Node/NodeFactory.php @@ -36,8 +36,6 @@ use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\Property; -use PhpParser\Node\Stmt\Use_; -use PhpParser\Node\Stmt\UseUse; use PHPStan\PhpDocParser\Ast\PhpDoc\GenericTagValueNode; use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode; use PHPStan\Type\Type; @@ -72,16 +70,6 @@ public function __construct( ) { } - /** - * Creates "SomeClass::CONSTANT" - * @deprecated - */ - public function createShortClassConstFetch(string $shortClassName, string $constantName): ClassConstFetch - { - $name = new Name($shortClassName); - return $this->createClassConstFetchFromName($name, $constantName); - } - /** * @param string|ObjectReference::* $className * Creates "\SomeClass::CONSTANT" @@ -205,6 +193,7 @@ public function createPrivatePropertyFromNameAndType(string $name, ?Type $type): } /** + * @api symfony * @param mixed[] $arguments */ public function createLocalMethodCall(string $method, array $arguments = []): MethodCall @@ -240,6 +229,9 @@ public function createParentConstructWithParams(array $params): StaticCall ); } + /** + * @api doctrine + */ public function createPrivateProperty(string $name): Property { $propertyBuilder = new PropertyBuilder($name); @@ -273,21 +265,6 @@ public function createConcat(array $exprs): ?Concat return $previousConcat; } - /** - * @param string[] $names - * @return Use_[] - */ - public function createUsesFromNames(array $names): array - { - $uses = []; - foreach ($names as $name) { - $useUse = new UseUse(new Name($name)); - $uses[] = new Use_([$useUse]); - } - - return $uses; - } - /** * @param string|ObjectReference::* $class * @param Node[] $args @@ -365,6 +342,7 @@ public function createTrue(): ConstFetch } /** + * @api phpunit * @param string|ObjectReference::* $constantName */ public function createClassConstFetchFromName(Name $className, string $constantName): ClassConstFetch diff --git a/src/PhpParser/Node/Value/ValueResolver.php b/src/PhpParser/Node/Value/ValueResolver.php index 0b91762bd43..1569860bdeb 100644 --- a/src/PhpParser/Node/Value/ValueResolver.php +++ b/src/PhpParser/Node/Value/ValueResolver.php @@ -97,6 +97,7 @@ public function getValue(Expr $expr, bool $resolvedClassReference = false): mixe } /** + * @api downgrade symfony * @param mixed[] $expectedValues */ public function isValues(Expr $expr, array $expectedValues): bool diff --git a/src/PhpParser/NodeTransformer.php b/src/PhpParser/NodeTransformer.php index 72f45e85ec0..f421d5b3662 100644 --- a/src/PhpParser/NodeTransformer.php +++ b/src/PhpParser/NodeTransformer.php @@ -28,6 +28,8 @@ final class NodeTransformer private const PERCENT_TEXT_REGEX = '#^%\w$#'; /** + * @api symfony + * * From: * - sprintf("Hi %s", $name); * @@ -86,6 +88,9 @@ public function transformArrayToYields(Array_ $array): array return $yieldNodes; } + /** + * @api symfony + */ public function transformConcatToStringArray(Concat $concat): Array_ { $arrayItems = $this->transformConcatToItems($concat); diff --git a/src/PhpParser/Parser/SimplePhpParser.php b/src/PhpParser/Parser/SimplePhpParser.php index c68b474b742..4a25a5689af 100644 --- a/src/PhpParser/Parser/SimplePhpParser.php +++ b/src/PhpParser/Parser/SimplePhpParser.php @@ -22,6 +22,7 @@ public function __construct() } /** + * @api tests * @return Stmt[] */ public function parseFile(string $filePath): array diff --git a/src/PhpParser/Printer/BetterStandardPrinter.php b/src/PhpParser/Printer/BetterStandardPrinter.php index 9e32fb048c8..ea19507b964 100644 --- a/src/PhpParser/Printer/BetterStandardPrinter.php +++ b/src/PhpParser/Printer/BetterStandardPrinter.php @@ -143,6 +143,9 @@ public function prettyPrintFile(array $stmts): string return parent::prettyPrintFile($stmts) . PHP_EOL; } + /** + * @api magic method in parent + */ public function pFileWithoutNamespace(FileWithoutNamespace $fileWithoutNamespace): string { $content = $this->pStmts($fileWithoutNamespace->stmts, false); diff --git a/src/PhpParser/Printer/FormatPerservingPrinter.php b/src/PhpParser/Printer/FormatPerservingPrinter.php index 9c8660709cb..6dea997bbb5 100644 --- a/src/PhpParser/Printer/FormatPerservingPrinter.php +++ b/src/PhpParser/Printer/FormatPerservingPrinter.php @@ -23,6 +23,8 @@ public function __construct( } /** + * @api tests + * * @param Node[] $newStmts * @param Node[] $oldStmts * @param Node[] $oldTokens diff --git a/src/Reporting/MissingRectorRulesReporter.php b/src/Reporting/MissingRectorRulesReporter.php index e40237ac4d9..14312913ab8 100644 --- a/src/Reporting/MissingRectorRulesReporter.php +++ b/src/Reporting/MissingRectorRulesReporter.php @@ -23,28 +23,10 @@ public function __construct( public function reportIfMissing(): ?int { - $activeRectors = array_filter( - $this->rectors, - static function (RectorInterface $rector): bool { - if ($rector instanceof PostRectorInterface) { - return false; - } - - return ! $rector instanceof ComplementaryRectorInterface; - } - ); - - if ($activeRectors !== []) { + if ($this->filterActiveRectors($this->rectors) !== []) { return null; } - $this->report(); - - return Command::FAILURE; - } - - public function report(): void - { $this->rectorOutputStyle->warning('We could not find any Rector rules to run. You have 2 options to add them:'); $this->rectorOutputStyle->title('1. Add single rule to "rector.php"'); @@ -58,5 +40,25 @@ public function report(): void $this->rectorOutputStyle->title('Missing "rector.php" in your project? Let Rector create it for you'); $this->rectorOutputStyle->writeln(' vendor/bin/rector init'); $this->rectorOutputStyle->newLine(); + + return Command::FAILURE; + } + + /** + * @param RectorInterface[] $rectors + * @return RectorInterface[] + */ + private function filterActiveRectors(array $rectors): array + { + return array_filter( + $rectors, + static function (RectorInterface $rector): bool { + if ($rector instanceof PostRectorInterface) { + return false; + } + + return ! $rector instanceof ComplementaryRectorInterface; + } + ); } } diff --git a/src/Util/ArrayParametersMerger.php b/src/Util/ArrayParametersMerger.php index 36fcf672e92..d501ab94f90 100644 --- a/src/Util/ArrayParametersMerger.php +++ b/src/Util/ArrayParametersMerger.php @@ -33,32 +33,6 @@ public function merge(mixed $left, mixed $right): mixed return $right; } - /** - * The same as above, just with the case if both values being non-array, it will combined them to array: - * - * $this->mergeWithCombine(1, 2); // [1, 2] - */ - public function mergeWithCombine(mixed $left, mixed $right): mixed - { - if (is_array($left) && is_array($right)) { - return $this->mergeLeftToRightWithCallable( - $left, - $right, - fn ($leftValue, $rightValue) => $this->mergeWithCombine($leftValue, $rightValue) - ); - } - - if ($left === null && is_array($right)) { - return $right; - } - - if (! empty($right) && (array) $left !== (array) $right) { - return $this->mergeWithCombine((array) $right, (array) $left); - } - - return $left; - } - /** * @param array $left * @param array $right diff --git a/src/Util/Reflection/PrivatesAccessor.php b/src/Util/Reflection/PrivatesAccessor.php index e5bf1660777..f92adc65456 100644 --- a/src/Util/Reflection/PrivatesAccessor.php +++ b/src/Util/Reflection/PrivatesAccessor.php @@ -32,22 +32,6 @@ public function callPrivateMethod(object|string $object, string $methodName, arr return $methodReflection->invokeArgs($object, $arguments); } - /** - * @param object|class-string $object - */ - public function callPrivateMethodWithReference(object|string $object, string $methodName, mixed $argument): mixed - { - if (is_string($object)) { - $reflectionClass = new ReflectionClass($object); - $object = $reflectionClass->newInstanceWithoutConstructor(); - } - - $methodReflection = $this->createAccessibleMethodReflection($object, $methodName); - $methodReflection->invokeArgs($object, [&$argument]); - - return $argument; - } - /** * @template T of object * diff --git a/src/Validation/RectorAssert.php b/src/Validation/RectorAssert.php index a8a7eaa8aa0..8963ca5a8d1 100644 --- a/src/Validation/RectorAssert.php +++ b/src/Validation/RectorAssert.php @@ -87,6 +87,9 @@ public static function functionName(string $name): void self::elementName($name, self::FUNCTION_NAME_REGEX, 'function'); } + /** + * @api + */ public static function elementName(string $name, string $regex, string $elementType): void { if (StringUtils::isMatch($name, $regex)) { diff --git a/src/ValueObject/Application/File.php b/src/ValueObject/Application/File.php index 8a3c5ae3d4e..2f899454894 100644 --- a/src/ValueObject/Application/File.php +++ b/src/ValueObject/Application/File.php @@ -67,11 +67,6 @@ public function changeFileContent(string $newFileContent): void $this->hasChanged = true; } - public function hasContentChanged(): bool - { - return $this->fileContent !== $this->originalFileContent; - } - public function getOriginalFileContent(): string { return $this->originalFileContent; diff --git a/src/ValueObject/Error/SystemError.php b/src/ValueObject/Error/SystemError.php index b6e7ba437a3..eab22a32f7a 100644 --- a/src/ValueObject/Error/SystemError.php +++ b/src/ValueObject/Error/SystemError.php @@ -32,11 +32,6 @@ public function getLine(): int|null return $this->line; } - public function getFileWithLine(): string - { - return $this->relativeFilePath . ':' . $this->line; - } - public function getRelativeFilePath(): ?string { return $this->relativeFilePath; diff --git a/tests/Util/Reflection/PrivatesAccessorTest.php b/tests/Util/Reflection/PrivatesAccessorTest.php index 10941d35d33..792b0e459b0 100644 --- a/tests/Util/Reflection/PrivatesAccessorTest.php +++ b/tests/Util/Reflection/PrivatesAccessorTest.php @@ -42,28 +42,6 @@ public function provideData(): Iterator yield [new SomeClassWithPrivateMethods(), 'plus10', [30], 40]; } - /** - * @dataProvider provideDataReference() - */ - public function testReference( - SomeClassWithPrivateMethods $someClassWithPrivateMethods, - string $methodName, - int $referencedArgument, - int $expectedResult - ): void { - $result = $this->privatesAccessor->callPrivateMethodWithReference( - $someClassWithPrivateMethods, - $methodName, - $referencedArgument - ); - $this->assertSame($expectedResult, $result); - } - - public function provideDataReference(): Iterator - { - yield [new SomeClassWithPrivateMethods(), 'multipleByTwo', 10, 20]; - } - public function testGetterSetter(): void { $privatesAccessor = new PrivatesAccessor(); diff --git a/utils/Compiler/Unprefixer.php b/utils/Compiler/Unprefixer.php index 827fcd25b8d..74947643942 100644 --- a/utils/Compiler/Unprefixer.php +++ b/utils/Compiler/Unprefixer.php @@ -14,6 +14,9 @@ final class Unprefixer */ private const QUOTED_VALUE_REGEX = '#\'\\\\(\w|@)#'; + /** + * @api + */ public static function unprefixQuoted(string $content, string $prefix): string { $match = sprintf('\'%s\\\\r\\\\n\'', $prefix); From 84f70604c6c1538722333ab6c9a2f301a66e7d51 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Fri, 23 Dec 2022 17:44:43 +0100 Subject: [PATCH 3/7] mics --- easy-ci.php | 2 - .../PhpDocInfo/PhpDocInfo.php | 19 --------- .../ValueObject/StartAndEnd.php | 9 ----- packages/Caching/CacheFactory.php | 3 ++ .../SameClassMethodCallAnalyzer.php | 39 ------------------- .../NodeTypeResolver/NodeTypeResolver.php | 1 + .../TypeAnalyzer/MethodTypeAnalyzer.php | 1 + .../FileInfoDeletionAnalyzer.php | 2 +- 8 files changed, 6 insertions(+), 70 deletions(-) delete mode 100644 packages/Defluent/NodeAnalyzer/SameClassMethodCallAnalyzer.php diff --git a/easy-ci.php b/easy-ci.php index 1058648cd43..bd9d8a26b8e 100644 --- a/easy-ci.php +++ b/easy-ci.php @@ -17,7 +17,6 @@ use Rector\Core\NodeDecorator\NamespacedNameDecorator; use Rector\Core\NodeManipulator\MethodCallManipulator; use Rector\Core\PhpParser\Node\NamedVariableFactory; -use Rector\Defluent\NodeAnalyzer\SameClassMethodCallAnalyzer; use Rector\DependencyInjection\NodeManipulator\PropertyConstructorInjectionManipulator; use Rector\FileSystemRector\Parser\FileInfoParser; use Rector\Naming\Contract\AssignVariableNameResolverInterface; @@ -80,7 +79,6 @@ PropertyConstructorInjectionManipulator::class, // used in tests FileInfoParser::class, - SameClassMethodCallAnalyzer::class, AnnotationToAttributeMapperInterface::class, TypeWithClassTypeSpecifierInterface::class, ParentNodeReadAnalyzerInterface::class, diff --git a/packages/BetterPhpDocParser/PhpDocInfo/PhpDocInfo.php b/packages/BetterPhpDocParser/PhpDocInfo/PhpDocInfo.php index c1b60585024..8fa8607a81b 100644 --- a/packages/BetterPhpDocParser/PhpDocInfo/PhpDocInfo.php +++ b/packages/BetterPhpDocParser/PhpDocInfo/PhpDocInfo.php @@ -397,25 +397,6 @@ public function getTemplateTagValueNodes(): array return $this->phpDocNode->getTemplateTagValues(); } - public function hasInheritDoc(): bool - { - if ($this->hasByNames(['inheritdoc', 'inheritDoc'])) { - return true; - } - - foreach ($this->phpDocNode->children as $children) { - if (! $children instanceof PhpDocTextNode) { - continue; - } - - if (in_array($children->text, ['{@inheritdoc}', '{@inheritDoc}'], true)) { - return true; - } - } - - return false; - } - /** * @deprecated * Should be handled by attributes of phpdoc node - if stard_and_end is missing in one of nodes, it has been changed diff --git a/packages/BetterPhpDocParser/ValueObject/StartAndEnd.php b/packages/BetterPhpDocParser/ValueObject/StartAndEnd.php index 9517eb0b591..b76b63ac450 100644 --- a/packages/BetterPhpDocParser/ValueObject/StartAndEnd.php +++ b/packages/BetterPhpDocParser/ValueObject/StartAndEnd.php @@ -26,13 +26,4 @@ public function getEnd(): int { return $this->end; } - - public function contains(int $position): bool - { - if ($position < $this->start) { - return false; - } - - return $position < $this->end; - } } diff --git a/packages/Caching/CacheFactory.php b/packages/Caching/CacheFactory.php index fd413d82efc..b8820a9ed06 100644 --- a/packages/Caching/CacheFactory.php +++ b/packages/Caching/CacheFactory.php @@ -18,6 +18,9 @@ public function __construct( ) { } + /** + * @api config factory + */ public function create(): Cache { $cacheDirectory = $this->parameterProvider->provideStringParameter(Option::CACHE_DIR); diff --git a/packages/Defluent/NodeAnalyzer/SameClassMethodCallAnalyzer.php b/packages/Defluent/NodeAnalyzer/SameClassMethodCallAnalyzer.php deleted file mode 100644 index 8cbfea2052c..00000000000 --- a/packages/Defluent/NodeAnalyzer/SameClassMethodCallAnalyzer.php +++ /dev/null @@ -1,39 +0,0 @@ -reflectionResolver->resolveMethodReflectionFromMethodCall($chainMethodCall); - - if ($methodReflection instanceof MethodReflection) { - $declaringClass = $methodReflection->getDeclaringClass(); - $classOfClassMethod[] = $declaringClass->getName(); - } else { - $classOfClassMethod[] = null; - } - } - - $uniqueClasses = array_unique($classOfClassMethod); - return count($uniqueClasses) < 2; - } -} diff --git a/packages/NodeTypeResolver/NodeTypeResolver.php b/packages/NodeTypeResolver/NodeTypeResolver.php index 141680a5bf2..ded2189b8fa 100644 --- a/packages/NodeTypeResolver/NodeTypeResolver.php +++ b/packages/NodeTypeResolver/NodeTypeResolver.php @@ -76,6 +76,7 @@ public function __construct( } /** + * @api doctrine symfony * @param ObjectType[] $requiredTypes */ public function isObjectTypes(Node $node, array $requiredTypes): bool diff --git a/packages/NodeTypeResolver/TypeAnalyzer/MethodTypeAnalyzer.php b/packages/NodeTypeResolver/TypeAnalyzer/MethodTypeAnalyzer.php index b068582c555..220aa703ca5 100644 --- a/packages/NodeTypeResolver/TypeAnalyzer/MethodTypeAnalyzer.php +++ b/packages/NodeTypeResolver/TypeAnalyzer/MethodTypeAnalyzer.php @@ -19,6 +19,7 @@ public function __construct( } /** + * @api downgrade * @param class-string $expectedClass * @param non-empty-string $expectedMethod */ diff --git a/rules/PSR4/FileInfoAnalyzer/FileInfoDeletionAnalyzer.php b/rules/PSR4/FileInfoAnalyzer/FileInfoDeletionAnalyzer.php index de6a8750fe4..5dd358eb003 100644 --- a/rules/PSR4/FileInfoAnalyzer/FileInfoDeletionAnalyzer.php +++ b/rules/PSR4/FileInfoAnalyzer/FileInfoDeletionAnalyzer.php @@ -37,7 +37,7 @@ public function isClassLikeAndFileInfoMatch(File $file, ClassLike $classLike): b return $baseFileName === $classShortName; } - public function clearNameFromTestingPrefix(string $name): string + private function clearNameFromTestingPrefix(string $name): string { return Strings::replace($name, self::TESTING_PREFIX_REGEX, ''); } From 28c02aea7a640ca0018473f8b2da1b7856965092 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Fri, 23 Dec 2022 17:45:44 +0100 Subject: [PATCH 4/7] remove type --- packages/BetterPhpDocParser/PhpDocInfo/PhpDocInfo.php | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/packages/BetterPhpDocParser/PhpDocInfo/PhpDocInfo.php b/packages/BetterPhpDocParser/PhpDocInfo/PhpDocInfo.php index 8fa8607a81b..580310c7aa4 100644 --- a/packages/BetterPhpDocParser/PhpDocInfo/PhpDocInfo.php +++ b/packages/BetterPhpDocParser/PhpDocInfo/PhpDocInfo.php @@ -154,16 +154,6 @@ public function getReturnType(): Type return $this->getTypeOrMixed($this->getReturnTagValue()); } - /** - * @template TNode as \PHPStan\PhpDocParser\Ast\Node - * @param class-string $type - * @return TNode[] - */ - public function getByType(string $type): array - { - return $this->phpDocNodeByTypeFinder->findByType($this->phpDocNode, $type); - } - /** * @param class-string $type */ From e84792dd1d2802177fba4c223cb3a1467c311068 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Fri, 23 Dec 2022 17:45:57 +0100 Subject: [PATCH 5/7] inliner var --- ...esolveTagToKnownFullyQualifiedNameTest.php | 8 ++-- .../PhpDocInfo/PhpDocInfo.php | 16 +------- .../VarAnnotationManipulator.php | 40 ------------------- .../StaticDoctrineAnnotationParser.php | 1 + .../NodeAnalyzer/ClassChildAnalyzer.php | 25 ++++++++++++ .../ValueObject/ControlStructure.php | 14 ------- packages/NodeRemoval/NodeRemover.php | 16 ++++++++ phpstan.neon | 4 ++ src/Kernel/RectorKernel.php | 3 ++ 9 files changed, 55 insertions(+), 72 deletions(-) diff --git a/packages-tests/BetterPhpDocParser/PhpDocParser/ClassAnnotationMatcher/ResolveTagToKnownFullyQualifiedNameTest.php b/packages-tests/BetterPhpDocParser/PhpDocParser/ClassAnnotationMatcher/ResolveTagToKnownFullyQualifiedNameTest.php index 19c879886af..861b3f91177 100644 --- a/packages-tests/BetterPhpDocParser/PhpDocParser/ClassAnnotationMatcher/ResolveTagToKnownFullyQualifiedNameTest.php +++ b/packages-tests/BetterPhpDocParser/PhpDocParser/ClassAnnotationMatcher/ResolveTagToKnownFullyQualifiedNameTest.php @@ -50,9 +50,11 @@ public function testResolvesClass(string $filePath): void foreach ($properties as $property) { /** @var Property $property */ $phpDoc = $this->phpDocInfoFactory->createFromNodeOrEmpty($property); - /** @var VarTagValueNode $varTag */ - $varTag = $phpDoc->getByType(VarTagValueNode::class)[0]; - $value = $varTag->type->__toString(); + + $varTagValueNode = $phpDoc->getVarTagValueNode(); + $this->assertInstanceOf(VarTagValueNode::class, $varTagValueNode); + + $value = $varTagValueNode->type->__toString(); $propertyName = strtolower($this->nodeNameResolver->getName($property)); $result = $this->classAnnotationMatcher->resolveTagToKnownFullyQualifiedName($value, $property); diff --git a/packages/BetterPhpDocParser/PhpDocInfo/PhpDocInfo.php b/packages/BetterPhpDocParser/PhpDocInfo/PhpDocInfo.php index 580310c7aa4..99153fad0e6 100644 --- a/packages/BetterPhpDocParser/PhpDocInfo/PhpDocInfo.php +++ b/packages/BetterPhpDocParser/PhpDocInfo/PhpDocInfo.php @@ -12,7 +12,6 @@ use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocNode; use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode; use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagValueNode; -use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTextNode; use PHPStan\PhpDocParser\Ast\PhpDoc\PropertyTagValueNode; use PHPStan\PhpDocParser\Ast\PhpDoc\ReturnTagValueNode; use PHPStan\PhpDocParser\Ast\PhpDoc\TemplateTagValueNode; @@ -421,19 +420,6 @@ public function hasChanged(): bool return $changedPhpDocNodeVisitor->hasChanged(); } - /** - * @return string[] - */ - public function getMethodTagNames(): array - { - $methodTagNames = []; - foreach ($this->phpDocNode->getMethodTagValues() as $methodTagValueNode) { - $methodTagNames[] = $methodTagValueNode->methodName; - } - - return $methodTagNames; - } - public function makeMultiLined(): void { $this->isSingleLine = false; @@ -444,7 +430,7 @@ public function getNode(): \PhpParser\Node return $this->node; } - public function resolveNameForPhpDocTagValueNode(PhpDocTagValueNode $phpDocTagValueNode): ?string + private function resolveNameForPhpDocTagValueNode(PhpDocTagValueNode $phpDocTagValueNode): ?string { foreach (self::TAGS_TYPES_TO_NAMES as $tagValueNodeType => $name) { /** @var class-string $tagValueNodeType */ diff --git a/packages/BetterPhpDocParser/PhpDocManipulator/VarAnnotationManipulator.php b/packages/BetterPhpDocParser/PhpDocManipulator/VarAnnotationManipulator.php index 126e0d57bdb..60d752ee47e 100644 --- a/packages/BetterPhpDocParser/PhpDocManipulator/VarAnnotationManipulator.php +++ b/packages/BetterPhpDocParser/PhpDocManipulator/VarAnnotationManipulator.php @@ -5,44 +5,18 @@ namespace Rector\BetterPhpDocParser\PhpDocManipulator; use PhpParser\Node; -use PhpParser\Node\Stmt\Expression; -use PHPStan\PhpDocParser\Ast\PhpDoc\VarTagValueNode; use PHPStan\Type\MixedType; use PHPStan\Type\Type; -use PHPStan\Type\TypeWithClassName; -use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo; use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory; -use Rector\BetterPhpDocParser\ValueObject\Type\FullyQualifiedIdentifierTypeNode; -use Rector\Core\PhpParser\Node\BetterNodeFinder; final class VarAnnotationManipulator { public function __construct( private readonly PhpDocInfoFactory $phpDocInfoFactory, private readonly PhpDocTypeChanger $phpDocTypeChanger, - private readonly BetterNodeFinder $betterNodeFinder ) { } - public function decorateNodeWithInlineVarType( - Node $node, - TypeWithClassName $typeWithClassName, - string $variableName - ): void { - $phpDocInfo = $this->resolvePhpDocInfo($node); - - // already done - if ($phpDocInfo->getVarTagValueNode() !== null) { - return; - } - - $fullyQualifiedIdentifierTypeNode = new FullyQualifiedIdentifierTypeNode($typeWithClassName->getClassName()); - - $varTagValueNode = new VarTagValueNode($fullyQualifiedIdentifierTypeNode, '$' . $variableName, ''); - $phpDocInfo->addTagValueNode($varTagValueNode); - $phpDocInfo->makeSingleLined(); - } - /** * @api */ @@ -55,18 +29,4 @@ public function decorateNodeWithType(Node $node, Type $staticType): void $phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($node); $this->phpDocTypeChanger->changeVarType($phpDocInfo, $staticType); } - - private function resolvePhpDocInfo(Node $node): PhpDocInfo - { - $currentStmt = $this->betterNodeFinder->resolveCurrentStatement($node); - if ($currentStmt instanceof Expression) { - $phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($currentStmt); - } else { - $phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($node); - } - - $phpDocInfo->makeSingleLined(); - - return $phpDocInfo; - } } diff --git a/packages/BetterPhpDocParser/PhpDocParser/StaticDoctrineAnnotationParser.php b/packages/BetterPhpDocParser/PhpDocParser/StaticDoctrineAnnotationParser.php index f637e5519b5..1a1e4ab09ee 100644 --- a/packages/BetterPhpDocParser/PhpDocParser/StaticDoctrineAnnotationParser.php +++ b/packages/BetterPhpDocParser/PhpDocParser/StaticDoctrineAnnotationParser.php @@ -47,6 +47,7 @@ public function resolveAnnotationMethodCall(BetterTokenIterator $tokenIterator): } /** + * @api tests * @see https://github.com/doctrine/annotations/blob/c66f06b7c83e9a2a7523351a9d5a4b55f885e574/lib/Doctrine/Common/Annotations/DocParser.php#L1215-L1224 * @return CurlyListNode|string|array|ConstExprNode|DoctrineAnnotationTagValueNode */ diff --git a/packages/FamilyTree/NodeAnalyzer/ClassChildAnalyzer.php b/packages/FamilyTree/NodeAnalyzer/ClassChildAnalyzer.php index fdad7e55b7d..c1462fdcf24 100644 --- a/packages/FamilyTree/NodeAnalyzer/ClassChildAnalyzer.php +++ b/packages/FamilyTree/NodeAnalyzer/ClassChildAnalyzer.php @@ -5,7 +5,10 @@ namespace Rector\FamilyTree\NodeAnalyzer; use PHPStan\Reflection\ClassReflection; +use PHPStan\Reflection\ParametersAcceptorSelector; use PHPStan\Reflection\Php\PhpMethodReflection; +use PHPStan\Type\MixedType; +use PHPStan\Type\Type; use Rector\FamilyTree\Reflection\FamilyRelationsAnalyzer; final class ClassChildAnalyzer @@ -62,6 +65,28 @@ public function hasAbstractParentClassMethod(ClassReflection $classReflection, s return false; } + /** + * @api downgrade + */ + public function resolveParentClassMethodReturnType(ClassReflection $classReflection, string $methodName): Type + { + $parentClassMethods = $this->resolveParentClassMethods($classReflection, $methodName); + if ($parentClassMethods === []) { + return new MixedType(); + } + + foreach ($parentClassMethods as $parentClassMethod) { + $parametersAcceptor = ParametersAcceptorSelector::selectSingle($parentClassMethod->getVariants()); + $nativeReturnType = $parametersAcceptor->getNativeReturnType(); + + if (! $nativeReturnType instanceof MixedType) { + return $nativeReturnType; + } + } + + return new MixedType(); + } + /** * @return PhpMethodReflection[] */ diff --git a/packages/NodeNestingScope/ValueObject/ControlStructure.php b/packages/NodeNestingScope/ValueObject/ControlStructure.php index b5dee3a959e..21a810ba7b0 100644 --- a/packages/NodeNestingScope/ValueObject/ControlStructure.php +++ b/packages/NodeNestingScope/ValueObject/ControlStructure.php @@ -5,35 +5,21 @@ namespace Rector\NodeNestingScope\ValueObject; use PhpParser\Node; -use PhpParser\Node\Expr\ArrowFunction; -use PhpParser\Node\Expr\Closure; use PhpParser\Node\Expr\Match_; use PhpParser\Node\FunctionLike; use PhpParser\Node\Stmt\Case_; use PhpParser\Node\Stmt\Catch_; -use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\Do_; use PhpParser\Node\Stmt\Else_; use PhpParser\Node\Stmt\ElseIf_; use PhpParser\Node\Stmt\For_; use PhpParser\Node\Stmt\Foreach_; -use PhpParser\Node\Stmt\Function_; use PhpParser\Node\Stmt\If_; use PhpParser\Node\Stmt\Switch_; use PhpParser\Node\Stmt\While_; final class ControlStructure { - /** - * @var array> - */ - public const RETURN_ISOLATING_SCOPE_NODE_TYPES = [ - Function_::class, - ClassMethod::class, - Closure::class, - ArrowFunction::class, - ]; - /** * @var array> */ diff --git a/packages/NodeRemoval/NodeRemover.php b/packages/NodeRemoval/NodeRemover.php index 4aecc0d98f9..d8b7dc8db19 100644 --- a/packages/NodeRemoval/NodeRemover.php +++ b/packages/NodeRemoval/NodeRemover.php @@ -5,6 +5,7 @@ namespace Rector\NodeRemoval; use PhpParser\Node; +use PhpParser\Node\Expr\Closure; use PhpParser\Node\Expr\FuncCall; use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Expr\StaticCall; @@ -97,4 +98,19 @@ public function removeArg(FuncCall | MethodCall | StaticCall $node, int $key): v unset($node->args[$key]); } + + /** + * @api phpunit + */ + public function removeStmt(Closure | ClassMethod | Function_ $functionLike, int $key): void + { + if ($functionLike->stmts === null) { + throw new ShouldNotHappenException(); + } + + // notify about remove node + $this->rectorChangeCollector->notifyNodeFileInfo($functionLike->stmts[$key]); + + unset($functionLike->stmts[$key]); + } } diff --git a/phpstan.neon b/phpstan.neon index 2cbe7a85c47..5979feb8859 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -887,3 +887,7 @@ parameters: path: packages-tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfo/PhpDocInfoTest.php - '#Symfony\\Component\\DependencyInjection\\Loader\\Configurator\\service not found#' + + # false positive + - '#Public method "Rector\\PhpAttribute\\NodeFactory\\DoctrineAnnotationFactory\:\:createFromAttribute\(\)" is never used#' + diff --git a/src/Kernel/RectorKernel.php b/src/Kernel/RectorKernel.php index 0733d7f311c..4bb13133000 100644 --- a/src/Kernel/RectorKernel.php +++ b/src/Kernel/RectorKernel.php @@ -27,6 +27,9 @@ public function __construct() $this->configureCallValuesCollector = new ConfigureCallValuesCollector(); } + /** + * @api used in tests + */ public function create(): ContainerInterface { return $this->createFromConfigs([]); From d61ebcc1475587055d29a630e17e24a0cca24792 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Fri, 23 Dec 2022 17:56:48 +0100 Subject: [PATCH 6/7] remove unsupported doc --- .../private_property_with_var_doc.php.inc | 38 ------------------- 1 file changed, 38 deletions(-) delete mode 100644 rules-tests/TypeDeclaration/Rector/Property/TypedPropertyFromStrictGetterMethodReturnTypeRector/FixturePhp73/private_property_with_var_doc.php.inc diff --git a/rules-tests/TypeDeclaration/Rector/Property/TypedPropertyFromStrictGetterMethodReturnTypeRector/FixturePhp73/private_property_with_var_doc.php.inc b/rules-tests/TypeDeclaration/Rector/Property/TypedPropertyFromStrictGetterMethodReturnTypeRector/FixturePhp73/private_property_with_var_doc.php.inc deleted file mode 100644 index 912c0979188..00000000000 --- a/rules-tests/TypeDeclaration/Rector/Property/TypedPropertyFromStrictGetterMethodReturnTypeRector/FixturePhp73/private_property_with_var_doc.php.inc +++ /dev/null @@ -1,38 +0,0 @@ -name; - } -} - -?> ------ -name; - } -} - -?> From 2a25eb98f410756b4f6cb8ff8f8d6e801c9de358 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Fri, 23 Dec 2022 17:57:04 +0100 Subject: [PATCH 7/7] remove testing on PHP 7.3, as never used --- ...ip_override_existing_type_by_mixed.php.inc | 23 --------------- ...tGetterMethodReturnTypePhp73RectorTest.php | 29 ------------------- .../config/rule_php73.php | 13 --------- src/Util/Reflection/PrivatesAccessor.php | 4 +-- 4 files changed, 2 insertions(+), 67 deletions(-) delete mode 100644 rules-tests/TypeDeclaration/Rector/Property/TypedPropertyFromStrictGetterMethodReturnTypeRector/FixturePhp73/skip_override_existing_type_by_mixed.php.inc delete mode 100644 rules-tests/TypeDeclaration/Rector/Property/TypedPropertyFromStrictGetterMethodReturnTypeRector/TypedPropertyFromStrictGetterMethodReturnTypePhp73RectorTest.php delete mode 100644 rules-tests/TypeDeclaration/Rector/Property/TypedPropertyFromStrictGetterMethodReturnTypeRector/config/rule_php73.php diff --git a/rules-tests/TypeDeclaration/Rector/Property/TypedPropertyFromStrictGetterMethodReturnTypeRector/FixturePhp73/skip_override_existing_type_by_mixed.php.inc b/rules-tests/TypeDeclaration/Rector/Property/TypedPropertyFromStrictGetterMethodReturnTypeRector/FixturePhp73/skip_override_existing_type_by_mixed.php.inc deleted file mode 100644 index 589ad213a1b..00000000000 --- a/rules-tests/TypeDeclaration/Rector/Property/TypedPropertyFromStrictGetterMethodReturnTypeRector/FixturePhp73/skip_override_existing_type_by_mixed.php.inc +++ /dev/null @@ -1,23 +0,0 @@ - - */ - private $rules = []; - - /** - * @return array - */ - public function getRules(): array - { - return $this->rules; - } -} - -?> diff --git a/rules-tests/TypeDeclaration/Rector/Property/TypedPropertyFromStrictGetterMethodReturnTypeRector/TypedPropertyFromStrictGetterMethodReturnTypePhp73RectorTest.php b/rules-tests/TypeDeclaration/Rector/Property/TypedPropertyFromStrictGetterMethodReturnTypeRector/TypedPropertyFromStrictGetterMethodReturnTypePhp73RectorTest.php deleted file mode 100644 index 91c03429b86..00000000000 --- a/rules-tests/TypeDeclaration/Rector/Property/TypedPropertyFromStrictGetterMethodReturnTypeRector/TypedPropertyFromStrictGetterMethodReturnTypePhp73RectorTest.php +++ /dev/null @@ -1,29 +0,0 @@ -doTestFile($filePath); - } - - public function provideData(): Iterator - { - return $this->yieldFilesFromDirectory(__DIR__ . '/FixturePhp73'); - } - - public function provideConfigFilePath(): string - { - return __DIR__ . '/config/rule_php73.php'; - } -} diff --git a/rules-tests/TypeDeclaration/Rector/Property/TypedPropertyFromStrictGetterMethodReturnTypeRector/config/rule_php73.php b/rules-tests/TypeDeclaration/Rector/Property/TypedPropertyFromStrictGetterMethodReturnTypeRector/config/rule_php73.php deleted file mode 100644 index 84fae95aa71..00000000000 --- a/rules-tests/TypeDeclaration/Rector/Property/TypedPropertyFromStrictGetterMethodReturnTypeRector/config/rule_php73.php +++ /dev/null @@ -1,13 +0,0 @@ -rule(TypedPropertyFromStrictGetterMethodReturnTypeRector::class); - - $rectorConfig->phpVersion(PhpVersionFeature::TYPED_PROPERTIES - 1); -}; diff --git a/src/Util/Reflection/PrivatesAccessor.php b/src/Util/Reflection/PrivatesAccessor.php index f92adc65456..1bac5e54b5c 100644 --- a/src/Util/Reflection/PrivatesAccessor.php +++ b/src/Util/Reflection/PrivatesAccessor.php @@ -27,9 +27,9 @@ public function callPrivateMethod(object|string $object, string $methodName, arr $object = $reflectionClass->newInstanceWithoutConstructor(); } - $methodReflection = $this->createAccessibleMethodReflection($object, $methodName); + $reflectionMethod = $this->createAccessibleMethodReflection($object, $methodName); - return $methodReflection->invokeArgs($object, $arguments); + return $reflectionMethod->invokeArgs($object, $arguments); } /**