diff --git a/.github/workflows/code_analysis.yaml b/.github/workflows/code_analysis.yaml index c52fc4e6d46..6adba4467ee 100644 --- a/.github/workflows/code_analysis.yaml +++ b/.github/workflows/code_analysis.yaml @@ -37,9 +37,9 @@ jobs: name: 'Commented Code' run: vendor/bin/easy-ci check-commented-code src packages rules tests packages-tests rules-tests --line-limit 5 --ansi -# - -# name: 'Active Classes' -# run: vendor/bin/easy-ci check-active-class src packages rules --ansi + - + name: 'Active Classes' + run: vendor/bin/easy-ci check-active-class bin config src packages rules --ansi # see https://github.com/rectorphp/rector-generator - diff --git a/easy-ci.php b/easy-ci.php index b1ff8852dca..b33502d2d35 100644 --- a/easy-ci.php +++ b/easy-ci.php @@ -2,18 +2,27 @@ declare(strict_types=1); +use PHPStan\PhpDocParser\Parser\TypeParser; use Rector\CodingStyle\Contract\ClassNameImport\ClassNameImportSkipVoterInterface; +use Rector\Core\Contract\Console\OutputStyleInterface; use Rector\Core\Contract\PHPStan\Reflection\TypeToCallReflectionResolver\TypeToCallReflectionResolverInterface; use Rector\Core\Contract\Processor\FileProcessorInterface; use Rector\Core\Contract\Rector\RectorInterface; +use Rector\Core\NodeManipulator\MethodCallManipulator; +use Rector\DependencyInjection\NodeManipulator\PropertyConstructorInjectionManipulator; +use Rector\FileFormatter\Contract\Formatter\FileFormatterInterface; +use Rector\Naming\Contract\Guard\ConflictingNameGuardInterface; use Rector\NodeNameResolver\Contract\NodeNameResolverInterface; use Rector\NodeTypeResolver\Contract\NodeTypeResolverInterface; +use Rector\NodeTypeResolver\DependencyInjection\PHPStanServicesFactory; +use Rector\NodeTypeResolver\Reflection\BetterReflection\RectorBetterReflectionSourceLocatorFactory; use Rector\Php80\Contract\StrStartWithMatchAndRefactorInterface; use Rector\PHPStanStaticTypeMapper\Contract\TypeMapperInterface; use Rector\ReadWrite\Contract\ReadNodeAnalyzerInterface; use Rector\Set\Contract\SetListInterface; use Rector\StaticTypeMapper\Contract\PhpDocParser\PhpDocTypeMapperInterface; use Rector\StaticTypeMapper\Contract\PhpParser\PhpParserNodeMapperInterface; +use Rector\Testing\PHPUnit\AbstractTestCase; use Rector\TypeDeclaration\Contract\TypeInferer\ParamTypeInfererInterface; use Rector\TypeDeclaration\Contract\TypeInferer\PropertyTypeInfererInterface; use Rector\TypeDeclaration\Contract\TypeInferer\ReturnTypeInfererInterface; @@ -44,5 +53,18 @@ return static function (ContainerConfigurator $containerConfigurator): void { NodeTypeResolverInterface::class, ReadNodeAnalyzerInterface::class, SetListInterface::class, + ConflictingNameGuardInterface::class, + TypeParser::class, + RectorBetterReflectionSourceLocatorFactory::class, + AbstractTestCase::class, + PHPStanServicesFactory::class, + OutputStyleInterface::class, + FileFormatterInterface::class, + MethodCallManipulator::class, + // fix later - rector-symfony + PropertyConstructorInjectionManipulator::class, + // used in tests + \Rector\FileSystemRector\Parser\FileInfoParser::class, + \Rector\Defluent\NodeAnalyzer\SameClassMethodCallAnalyzer::class, ]); }; diff --git a/packages-tests/BetterPhpDocParser/PhpDocParser/TypeNodeAnalyzerTest.php b/packages-tests/BetterPhpDocParser/PhpDocParser/TypeNodeAnalyzerTest.php deleted file mode 100644 index f668891dbbc..00000000000 --- a/packages-tests/BetterPhpDocParser/PhpDocParser/TypeNodeAnalyzerTest.php +++ /dev/null @@ -1,47 +0,0 @@ -boot(); - $this->typeNodeAnalyzer = $this->getService(TypeNodeAnalyzer::class); - } - - /** - * @dataProvider provideDataForIntersectionAndNotNullable() - */ - public function testIsIntersectionAndNotNullable(TypeNode $typeNode, bool $expectedIs): void - { - $isIntersection = $this->typeNodeAnalyzer->isIntersectionAndNotNullable($typeNode); - $this->assertSame($expectedIs, $isIntersection); - } - - /** - * @return Iterator - */ - public function provideDataForIntersectionAndNotNullable(): Iterator - { - yield [new IntersectionTypeNode([new IdentifierTypeNode(self::INT)]), true]; - yield [new IntersectionTypeNode([new NullableTypeNode(new IdentifierTypeNode(self::INT))]), false]; - } -} diff --git a/packages/BetterPhpDocParser/PhpDocParser/TypeNodeAnalyzer.php b/packages/BetterPhpDocParser/PhpDocParser/TypeNodeAnalyzer.php deleted file mode 100644 index 513b305ad3e..00000000000 --- a/packages/BetterPhpDocParser/PhpDocParser/TypeNodeAnalyzer.php +++ /dev/null @@ -1,30 +0,0 @@ -types as $subType) { - if ($subType instanceof NullableTypeNode) { - return false; - } - } - - return true; - } -} diff --git a/packages/FamilyTree/NodeAnalyzer/PropertyUsageAnalyzer.php b/packages/FamilyTree/NodeAnalyzer/PropertyUsageAnalyzer.php deleted file mode 100644 index 4219b22a3fe..00000000000 --- a/packages/FamilyTree/NodeAnalyzer/PropertyUsageAnalyzer.php +++ /dev/null @@ -1,72 +0,0 @@ -getAttribute(AttributeKey::CLASS_NAME); - if ($className === null) { - return false; - } - - $scope = $property->getAttribute(AttributeKey::SCOPE); - if (! $scope instanceof Scope) { - return false; - } - - $classReflection = $scope->getClassReflection(); - if (! $classReflection instanceof ClassReflection) { - throw new ShouldNotHappenException(); - } - - if ($classReflection->isClass() && $classReflection->isFinal()) { - return false; - } - - $propertyName = $this->nodeNameResolver->getName($property); - - $childrenClassReflections = $this->familyRelationsAnalyzer->getChildrenOfClassReflection($classReflection); - - foreach ($childrenClassReflections as $childClassReflection) { - $childClass = $this->astResolver->resolveClassFromName($childClassReflection->getName()); - if (! $childClass instanceof Class_) { - continue; - } - - $isPropertyFetched = (bool) $this->betterNodeFinder->findFirst( - $childClass->stmts, - fn (Node $node): bool => $this->nodeNameResolver->isLocalPropertyFetchNamed($node, $propertyName) - ); - - if ($isPropertyFetched) { - return true; - } - } - - return false; - } -} diff --git a/packages/ListReporting/Contract/Output/ShowOutputFormatterInterface.php b/packages/ListReporting/Contract/Output/ShowOutputFormatterInterface.php deleted file mode 100644 index e7d799bc5c5..00000000000 --- a/packages/ListReporting/Contract/Output/ShowOutputFormatterInterface.php +++ /dev/null @@ -1,17 +0,0 @@ -outputStyle->title('Loaded Rector rules'); - - foreach ($rectors as $rector) { - $this->outputStyle->writeln(' * ' . $rector::class); - } - - $message = sprintf('%d loaded Rectors', $rectorCount); - $this->outputStyle->success($message); - } - - public function getName(): string - { - return self::NAME; - } -} diff --git a/packages/Testing/PHPUnit/PlatformAgnosticAssertions.php b/packages/Testing/PHPUnit/PlatformAgnosticAssertions.php deleted file mode 100644 index f11559c29c3..00000000000 --- a/packages/Testing/PHPUnit/PlatformAgnosticAssertions.php +++ /dev/null @@ -1,85 +0,0 @@ -params !== []) { - return; - } - - if ((array) $classMethod->stmts !== []) { - return; - } - - $this->nodesToRemoveCollector->addNodeToRemove($classMethod); - } - - public function removeParamFromMethodBody(ClassMethod $classMethod, Param $param): void - { - /** @var string $paramName */ - $paramName = $this->nodeNameResolver->getName($param->var); - - $this->simpleCallableNodeTraverser->traverseNodesWithCallable( - (array) $classMethod->stmts, - function (Node $node) use ($paramName) { - if (! $this->isParentConstructStaticCall($node)) { - return null; - } - - /** @var StaticCall $node */ - $this->removeParamFromArgs($node, $paramName); - - if ($node->args === []) { - $this->nodesToRemoveCollector->addNodeToRemove($node); - } - - return null; - } - ); - - foreach ((array) $classMethod->stmts as $key => $stmt) { - if ($stmt instanceof Expression) { - $stmt = $stmt->expr; - } - - if (! $this->isParentConstructStaticCall($stmt)) { - continue; - } - - /** @var StaticCall $stmt */ - if ($stmt->args !== []) { - continue; - } - - unset($classMethod->stmts[$key]); - } - - $this->removeParamFromAssign($classMethod, $paramName); - } - - private function isParentConstructStaticCall(Node $node): bool - { - if (! $node instanceof StaticCall) { - return false; - } - - if (! $this->nodeNameResolver->isName($node->class, ObjectReference::PARENT()->getValue())) { - return false; - } - - return $this->nodeNameResolver->isName($node->name, MethodName::CONSTRUCT); - } - - private function removeParamFromArgs(StaticCall $staticCall, string $paramName): void - { - foreach ($staticCall->args as $key => $arg) { - if (! $arg instanceof Arg) { - continue; - } - - if (! $this->nodeNameResolver->isName($arg->value, $paramName)) { - continue; - } - - unset($staticCall->args[$key]); - } - } - - private function removeParamFromAssign(ClassMethod $classMethod, string $paramName): void - { - foreach ((array) $classMethod->stmts as $key => $stmt) { - if ($stmt instanceof Expression) { - $stmt = $stmt->expr; - } - - if (! $stmt instanceof Assign) { - continue; - } - - if (! $stmt->expr instanceof Variable) { - continue; - } - - if (! $this->nodeNameResolver->isName($stmt->expr, $paramName)) { - continue; - } - - unset($classMethod->stmts[$key]); - } - } -} diff --git a/rules/DowngradePhp72/Contract/Rector/DowngradeTypeRectorInterface.php b/rules/DowngradePhp72/Contract/Rector/DowngradeTypeRectorInterface.php deleted file mode 100644 index 8529ddc1aab..00000000000 --- a/rules/DowngradePhp72/Contract/Rector/DowngradeTypeRectorInterface.php +++ /dev/null @@ -1,13 +0,0 @@ -simpleCallableNodeTraverser->traverseNodesWithCallable((array) $classMethod->stmts, function ( - Node $node - ) use ($arrayDimFetch, $variableName) { - // do not rename element above - if ($node->getLine() <= $arrayDimFetch->getLine()) { - return null; - } - - if ($this->isScopeNesting($node)) { - return NodeTraverser::DONT_TRAVERSE_CURRENT_AND_CHILDREN; - } - - if (! $this->nodeComparator->areNodesEqual($node, $arrayDimFetch)) { - return null; - } - - return new Variable($variableName); - }); - } - - private function isScopeNesting(Node $node): bool - { - return $node instanceof Closure || $node instanceof Function_ || $node instanceof ArrowFunction; - } -} diff --git a/rules/RemovingStatic/NodeFactory/SetUpFactory.php b/rules/RemovingStatic/NodeFactory/SetUpFactory.php deleted file mode 100644 index a9aa8cce195..00000000000 --- a/rules/RemovingStatic/NodeFactory/SetUpFactory.php +++ /dev/null @@ -1,24 +0,0 @@ -nodeFactory->createStaticCall(ObjectReference::PARENT(), MethodName::SET_UP); - return new Expression($parentSetupStaticCall); - } -} diff --git a/rules/Renaming/NodeManipulator/IdentifierManipulator.php b/rules/Renaming/NodeManipulator/IdentifierManipulator.php deleted file mode 100644 index 24ea523db4b..00000000000 --- a/rules/Renaming/NodeManipulator/IdentifierManipulator.php +++ /dev/null @@ -1,67 +0,0 @@ -resolveOldMethodName($node); - if ($oldNodeMethodName === null) { - return; - } - - $node->name = new Identifier($renameMethodMap[$oldNodeMethodName]); - } - - public function removeSuffix( - ClassConstFetch | MethodCall | PropertyFetch | StaticCall | ClassMethod $node, - string $suffixToRemove - ): void { - $name = $this->nodeNameResolver->getName($node); - if ($name === null) { - return; - } - - $newName = Strings::replace($name, sprintf('#%s$#', $suffixToRemove), ''); - $node->name = new Identifier($newName); - } - - private function resolveOldMethodName( - ClassConstFetch | MethodCall | PropertyFetch | StaticCall | ClassMethod $node - ): ?string { - if ($node instanceof StaticCall || $node instanceof MethodCall) { - return $this->nodeNameResolver->getName($node->name); - } - - return $this->nodeNameResolver->getName($node); - } -} diff --git a/rules/Transform/ValueObject/VariableMethodCallToServiceCall.php b/rules/Transform/ValueObject/VariableMethodCallToServiceCall.php deleted file mode 100644 index 0f357243eb9..00000000000 --- a/rules/Transform/ValueObject/VariableMethodCallToServiceCall.php +++ /dev/null @@ -1,50 +0,0 @@ -variableType); - } - - public function getMethodName(): string - { - return $this->methodName; - } - - /** - * @return mixed - */ - public function getArgumentValue() - { - return $this->argumentValue; - } - - public function getServiceType(): string - { - return $this->serviceType; - } - - public function getServiceMethodName(): string - { - return $this->serviceMethodName; - } -} diff --git a/src/Console/Command/ShowCommand.php b/src/Console/Command/ShowCommand.php index 7db3884a032..75f76d50577 100644 --- a/src/Console/Command/ShowCommand.php +++ b/src/Console/Command/ShowCommand.php @@ -4,16 +4,12 @@ declare(strict_types=1); namespace Rector\Core\Console\Command; -use Rector\ChangesReporting\Output\ConsoleOutputFormatter; -use Rector\Core\Configuration\Option; -use Rector\Core\Console\Output\ShowOutputFormatterCollector; use Rector\Core\Contract\Console\OutputStyleInterface; use Rector\Core\Contract\Rector\RectorInterface; use Rector\PostRector\Contract\Rector\ComplementaryRectorInterface; use Rector\PostRector\Contract\Rector\PostRectorInterface; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; -use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; final class ShowCommand extends Command @@ -23,7 +19,6 @@ final class ShowCommand extends Command */ public function __construct( private OutputStyleInterface $outputStyle, - private ShowOutputFormatterCollector $showOutputFormatterCollector, private array $rectors ) { parent::__construct(); @@ -32,30 +27,12 @@ final class ShowCommand extends Command protected function configure(): void { $this->setDescription('Show loaded Rectors with their configuration'); - - $names = $this->showOutputFormatterCollector->getNames(); - - $description = sprintf('Select output format: "%s".', implode('", "', $names)); - $this->addOption( - Option::OUTPUT_FORMAT, - 'o', - InputOption::VALUE_OPTIONAL, - $description, - ConsoleOutputFormatter::NAME - ); } protected function execute(InputInterface $input, OutputInterface $output): int { - $outputFormat = (string) $input->getOption(Option::OUTPUT_FORMAT); + $this->outputStyle->title('Loaded Rector rules'); - $this->reportLoadedRectors($outputFormat); - - return Command::SUCCESS; - } - - private function reportLoadedRectors(string $outputFormat): void - { $rectors = array_filter( $this->rectors, function (RectorInterface $rector): bool { @@ -76,11 +53,17 @@ final class ShowCommand extends Command PHP_EOL ); $this->outputStyle->warning($warningMessage); - - return; + return self::SUCCESS; } - $outputFormatter = $this->showOutputFormatterCollector->getByName($outputFormat); - $outputFormatter->list($rectors); + $rectorCount = count($rectors); + foreach ($rectors as $rector) { + $this->outputStyle->writeln(' * ' . $rector::class); + } + + $message = sprintf('%d loaded Rectors', $rectorCount); + $this->outputStyle->success($message); + + return Command::SUCCESS; } } diff --git a/src/Console/Output/ShowOutputFormatterCollector.php b/src/Console/Output/ShowOutputFormatterCollector.php deleted file mode 100644 index b0dd6c2851b..00000000000 --- a/src/Console/Output/ShowOutputFormatterCollector.php +++ /dev/null @@ -1,54 +0,0 @@ -outputFormatters[$showOutputFormatter->getName()] = $showOutputFormatter; - } - } - - public function getByName(string $name): ShowOutputFormatterInterface - { - $this->ensureOutputFormatExists($name); - - return $this->outputFormatters[$name]; - } - - /** - * @return int[]|string[] - */ - public function getNames(): array - { - return array_keys($this->outputFormatters); - } - - private function ensureOutputFormatExists(string $name): void - { - if (isset($this->outputFormatters[$name])) { - return; - } - - throw new InvalidConfigurationException(sprintf( - 'Output formatter "%s" was not found. Pick one of "%s".', - $name, - implode('", "', $this->getNames()) - )); - } -}