diff --git a/.github/workflows/code_analysis.yaml b/.github/workflows/code_analysis.yaml index 90d7111cd5f..c52fc4e6d46 100644 --- a/.github/workflows/code_analysis.yaml +++ b/.github/workflows/code_analysis.yaml @@ -34,9 +34,12 @@ jobs: run: composer phpstan-config - - name: Commented Code + 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 # see https://github.com/rectorphp/rector-generator - diff --git a/composer.json b/composer.json index 2aae2fe64c2..70ddb404994 100644 --- a/composer.json +++ b/composer.json @@ -26,10 +26,10 @@ "rector/rector-cakephp": "^0.11.6", "rector/rector-doctrine": "^0.11.26", "rector/rector-laravel": "^0.11.8", - "rector/rector-nette": "^0.11.31", + "rector/rector-nette": "^0.11.39", "rector/rector-phpoffice": "^0.11.6", "rector/rector-phpunit": "^0.11.16", - "rector/rector-symfony": "^0.11.31", + "rector/rector-symfony": "^0.11.33", "sebastian/diff": "^4.0.4", "ssch/typo3-rector": "^0.11.26", "symfony/console": "^5.3.7", diff --git a/easy-ci.php b/easy-ci.php new file mode 100644 index 00000000000..b1ff8852dca --- /dev/null +++ b/easy-ci.php @@ -0,0 +1,48 @@ +parameters(); + $parameters->set(Option::TYPES_TO_SKIP, [ + Command::class, + Application::class, + RectorInterface::class, + TypeToCallReflectionResolverInterface::class, + PropertyTypeInfererInterface::class, + ParamTypeInfererInterface::class, + ReturnTypeInfererInterface::class, + FileProcessorInterface::class, + ClassNameImportSkipVoterInterface::class, + StrStartWithMatchAndRefactorInterface::class, + PhpDocTypeMapperInterface::class, + PhpParserNodeMapperInterface::class, + TypeMapperInterface::class, + AbstractPhpDocNodeVisitor::class, + NodeNameResolverInterface::class, + NodeTypeResolverInterface::class, + ReadNodeAnalyzerInterface::class, + SetListInterface::class, + ]); +}; diff --git a/ecs.php b/ecs.php index 53d9a8fa64c..bdbd0fb4de3 100644 --- a/ecs.php +++ b/ecs.php @@ -50,6 +50,7 @@ __DIR__ . '/utils', __DIR__ . '/config', __DIR__ . '/ecs.php', + __DIR__ . '/easy-ci.php', __DIR__ . '/rector.php', __DIR__ . '/scoper.php', ]); diff --git a/packages/BetterPhpDocParser/ValueObject/AroundSpaces.php b/packages/BetterPhpDocParser/ValueObject/AroundSpaces.php deleted file mode 100644 index a2fe99460aa..00000000000 --- a/packages/BetterPhpDocParser/ValueObject/AroundSpaces.php +++ /dev/null @@ -1,24 +0,0 @@ -closingSpace; - } - - public function getOpeningSpace(): string - { - return $this->openingSpace; - } -} diff --git a/packages/BetterPhpDocParser/ValueObject/PhpDocNode/AbstractTagValueNode.php b/packages/BetterPhpDocParser/ValueObject/PhpDocNode/AbstractTagValueNode.php deleted file mode 100644 index ba020a56692..00000000000 --- a/packages/BetterPhpDocParser/ValueObject/PhpDocNode/AbstractTagValueNode.php +++ /dev/null @@ -1,24 +0,0 @@ - $items - */ - public function createFromItems(array $items): DoctrineAnnotationTagValueNode - { - return new DoctrineAnnotationTagValueNode( - new IdentifierTypeNode('Symfony\Component\Routing\Annotation\Route'), - null, - $items, - 'path' - ); - } -} diff --git a/packages/NodeTypeResolver/Exception/MissingTagException.php b/packages/NodeTypeResolver/Exception/MissingTagException.php deleted file mode 100644 index c2e2a958e10..00000000000 --- a/packages/NodeTypeResolver/Exception/MissingTagException.php +++ /dev/null @@ -1,11 +0,0 @@ -inputFilePath); - } - - public function getAddedFileWithContent(): AddedFileWithContent - { - return $this->addedFileWithContent; - } -} diff --git a/packages/VendorLocker/Contract/NodeVendorLockerInterface.php b/packages/VendorLocker/Contract/NodeVendorLockerInterface.php deleted file mode 100644 index 8d48221b426..00000000000 --- a/packages/VendorLocker/Contract/NodeVendorLockerInterface.php +++ /dev/null @@ -1,12 +0,0 @@ -resolveClassReflection($property); - if (! $classReflection instanceof ClassReflection) { - return false; - } - - $propertyName = $this->nodeNameResolver->getName($property); - - foreach ($classReflection->getParents() as $parentClassReflection) { - if ($parentClassReflection->hasProperty($propertyName)) { - return true; - } - } - - return false; - } - - public function isChildLockedProperty(Property $property): bool - { - $classReflection = $this->resolveClassReflection($property); - if (! $classReflection instanceof ClassReflection) { - return false; - } - - $propertyName = $this->nodeNameResolver->getName($property); - - $childrenClassReflections = $this->familyRelationsAnalyzer->getChildrenOfClassReflection($classReflection); - foreach ($childrenClassReflections as $childClassReflection) { - if ($childClassReflection === $classReflection) { - continue; - } - - if ($childClassReflection->hasProperty($propertyName)) { - return true; - } - } - - return false; - } - - private function resolveClassReflection(Property $property): ?ClassReflection - { - $scope = $property->getAttribute(AttributeKey::SCOPE); - if (! $scope instanceof Scope) { - return null; - } - - return $scope->getClassReflection(); - } -} diff --git a/rules/DependencyInjection/NodeFactory/InjectMethodFactory.php b/rules/DependencyInjection/NodeFactory/InjectMethodFactory.php deleted file mode 100644 index 780d9d7421b..00000000000 --- a/rules/DependencyInjection/NodeFactory/InjectMethodFactory.php +++ /dev/null @@ -1,66 +0,0 @@ -typeFactory->uniquateTypes($objectTypes); - - $shortClassName = $this->classNaming->getShortName($className); - - $methodBuilder = new MethodBuilder('inject' . $shortClassName); - $methodBuilder->makePublic(); - - foreach ($objectTypes as $objectType) { - /** @var ObjectType $objectType */ - $propertyName = $this->propertyNaming->fqnToVariableName($objectType); - - $paramBuilder = new ParamBuilder($propertyName); - $paramBuilder->setType(new FullyQualified($objectType->getClassName())); - $methodBuilder->addParam($paramBuilder); - - $assign = $this->nodeFactory->createPropertyAssignment($propertyName); - - $methodBuilder->addStmt($assign); - } - - $classMethod = $methodBuilder->getNode(); - - if ($framework === FrameworkName::SYMFONY) { - $phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($classMethod); - $phpDocInfo->addPhpDocTagNode(new PhpDocTagNode('@required', new GenericTagValueNode(''))); - } - - return $classMethod; - } -} diff --git a/rules/Naming/Naming/MethodNameResolver.php b/rules/Naming/Naming/MethodNameResolver.php deleted file mode 100644 index 4c59459a5f6..00000000000 --- a/rules/Naming/Naming/MethodNameResolver.php +++ /dev/null @@ -1,40 +0,0 @@ -variableNaming->resolveFromNode($expr); - if ($variableName === null) { - return null; - } - - return 'get' . ucfirst($variableName); - } - - public function resolveIsserFromReturnedExpr(Expr $expr): ?string - { - $variableName = $this->variableNaming->resolveFromNode($expr); - if ($variableName === null) { - return null; - } - - if (Strings::match($variableName, '#^(is)#')) { - return $variableName; - } - - return 'is' . ucfirst($variableName); - } -} diff --git a/rules/Order/Contract/RankeableInterface.php b/rules/Order/Contract/RankeableInterface.php deleted file mode 100644 index 194adf1b22f..00000000000 --- a/rules/Order/Contract/RankeableInterface.php +++ /dev/null @@ -1,15 +0,0 @@ - $oldToNewKeys - */ - public function hasOrderChanged(array $oldToNewKeys): bool - { - $keys = array_keys($oldToNewKeys); - $values = array_values($oldToNewKeys); - - return $keys !== $values; - } -} diff --git a/rules/Order/StmtVisibilitySorter.php b/rules/Order/StmtVisibilitySorter.php deleted file mode 100644 index aa6024796ea..00000000000 --- a/rules/Order/StmtVisibilitySorter.php +++ /dev/null @@ -1,134 +0,0 @@ -stmts as $position => $propertyStmt) { - if (! $propertyStmt instanceof Property) { - continue; - } - - /** @var string $propertyName */ - $propertyName = $this->nodeNameResolver->getName($propertyStmt); - - $propertyRankeables[] = new PropertyRankeable( - $propertyName, - $this->getVisibilityLevelOrder($propertyStmt), - $propertyStmt, - $position - ); - } - - return $this->sortByRanksAndGetNames($propertyRankeables); - } - - /** - * @return string[] - */ - public function sortMethods(ClassLike $classLike): array - { - $classMethodsRankeables = []; - - foreach ($classLike->stmts as $position => $classStmt) { - if (! $classStmt instanceof ClassMethod) { - continue; - } - - /** @var string $classMethodName */ - $classMethodName = $this->nodeNameResolver->getName($classStmt); - - $classMethodsRankeables[] = new ClassMethodRankeable( - $classMethodName, - $this->getVisibilityLevelOrder($classStmt), - $position, - $classStmt - ); - } - - return $this->sortByRanksAndGetNames($classMethodsRankeables); - } - - /** - * @return string[] - */ - public function sortConstants(Class_ | Interface_ $classLike): array - { - $classConstsRankeables = []; - foreach ($classLike->stmts as $position => $constantStmt) { - if (! $constantStmt instanceof ClassConst) { - continue; - } - - /** @var string $constantName */ - $constantName = $this->nodeNameResolver->getName($constantStmt); - - $classConstsRankeables[] = new ClassConstRankeable( - $constantName, - $this->getVisibilityLevelOrder($constantStmt), - $position - ); - } - - return $this->sortByRanksAndGetNames($classConstsRankeables); - } - - private function getVisibilityLevelOrder(ClassMethod | Property | ClassConst $stmt): int - { - if ($stmt->isPrivate()) { - return 2; - } - - if ($stmt->isProtected()) { - return 1; - } - - return 0; - } - - /** - * @param RankeableInterface[] $rankeables - * @return string[] - */ - private function sortByRanksAndGetNames(array $rankeables): array - { - uasort( - $rankeables, - fn (RankeableInterface $firstRankeable, RankeableInterface $secondRankeable): int => $firstRankeable->getRanks() <=> $secondRankeable->getRanks() - ); - - $names = []; - foreach ($rankeables as $rankeable) { - $names[] = $rankeable->getName(); - } - - return $names; - } -} diff --git a/rules/Order/ValueObject/ClassConstRankeable.php b/rules/Order/ValueObject/ClassConstRankeable.php deleted file mode 100644 index c994c69f0c1..00000000000 --- a/rules/Order/ValueObject/ClassConstRankeable.php +++ /dev/null @@ -1,31 +0,0 @@ -name; - } - - /** - * An array to sort the element order by - * @return int[] - */ - public function getRanks(): array - { - return [$this->visibility, $this->position]; - } -} diff --git a/rules/Order/ValueObject/ClassMethodRankeable.php b/rules/Order/ValueObject/ClassMethodRankeable.php deleted file mode 100644 index 52859e5c54d..00000000000 --- a/rules/Order/ValueObject/ClassMethodRankeable.php +++ /dev/null @@ -1,40 +0,0 @@ -name; - } - - /** - * An array to sort the element order by - * @return bool[]|int[] - */ - public function getRanks(): array - { - return [ - $this->visibility, - $this->classMethod->isStatic(), - // negated on purpose, to put abstract later - ! $this->classMethod->isAbstract(), - $this->classMethod->isFinal(), - $this->position, - ]; - } -} diff --git a/rules/Order/ValueObject/PropertyRankeable.php b/rules/Order/ValueObject/PropertyRankeable.php deleted file mode 100644 index 8d07e469091..00000000000 --- a/rules/Order/ValueObject/PropertyRankeable.php +++ /dev/null @@ -1,32 +0,0 @@ -name; - } - - /** - * @return bool[]|int[] - */ - public function getRanks(): array - { - return [$this->visibility, $this->property->isStatic(), $this->position]; - } -} diff --git a/rules/Privatization/NodeAnalyzer/EventSubscriberMethodNamesResolver.php b/rules/Privatization/NodeAnalyzer/EventSubscriberMethodNamesResolver.php deleted file mode 100644 index eaa56c4cec6..00000000000 --- a/rules/Privatization/NodeAnalyzer/EventSubscriberMethodNamesResolver.php +++ /dev/null @@ -1,43 +0,0 @@ -simpleCallableNodeTraverser->traverseNodesWithCallable( - (array) $classMethod->stmts, - function (Node $node) use (&$methodNames) { - if (! $node instanceof ArrayItem) { - return null; - } - - if (! $node->value instanceof String_) { - return null; - } - - $methodNames[] = $node->value->value; - } - ); - - return $methodNames; - } -} diff --git a/rules/Transform/NodeFactory/ClassMethodFactory.php b/rules/Transform/NodeFactory/ClassMethodFactory.php deleted file mode 100644 index 44d68f1b591..00000000000 --- a/rules/Transform/NodeFactory/ClassMethodFactory.php +++ /dev/null @@ -1,22 +0,0 @@ -makePublic(); - $methodBuilder->makeStatic(); - $methodBuilder->addStmts($function->stmts); - - return $methodBuilder->getNode(); - } -} diff --git a/rules/Transform/NodeFactory/ProvideConfigFilePathClassMethodFactory.php b/rules/Transform/NodeFactory/ProvideConfigFilePathClassMethodFactory.php deleted file mode 100644 index 1ebb70f0446..00000000000 --- a/rules/Transform/NodeFactory/ProvideConfigFilePathClassMethodFactory.php +++ /dev/null @@ -1,34 +0,0 @@ -nodeFactory->createPublicMethod('provideConfigFilePath'); - $classMethod->returnType = new Identifier('string'); - - $concat = new Concat(new Dir(), new String_('/config/configured_rule.php')); - $return = new Return_($concat); - - $classMethod->stmts[] = $return; - - return $classMethod; - } -} diff --git a/rules/Transform/ValueObject/FunctionToStaticCall.php b/rules/Transform/ValueObject/FunctionToStaticCall.php deleted file mode 100644 index 2867592b6f4..00000000000 --- a/rules/Transform/ValueObject/FunctionToStaticCall.php +++ /dev/null @@ -1,30 +0,0 @@ -class; - } - - public function getMethod(): string - { - return $this->method; - } - - public function getFunction(): string - { - return $this->function; - } -} diff --git a/rules/TypeDeclaration/Enum/TypeStrictness.php b/rules/TypeDeclaration/Enum/TypeStrictness.php deleted file mode 100644 index 5773066f524..00000000000 --- a/rules/TypeDeclaration/Enum/TypeStrictness.php +++ /dev/null @@ -1,25 +0,0 @@ -loadStubs(); - - $rectorKernel = new RectorKernel(); - return $rectorKernel->createFromConfigs($configFiles); - } - public function createFromBootstrapConfigs(BootstrapConfigs $bootstrapConfigs): ContainerInterface { $container = $this->createFromConfigs($bootstrapConfigs->getConfigFiles()); @@ -43,7 +27,15 @@ public function createFromBootstrapConfigs(BootstrapConfigs $bootstrapConfigs): } /** - * @see https://symfony.com/doc/current/components/dependency_injection/compilation.html#dumping-the-configuration-for-performance * @param string[] $configFiles + * @api */ + private function createFromConfigs(array $configFiles): ContainerInterface + { + $phpStanStubLoader = new PHPStanStubLoader(); + $phpStanStubLoader->loadStubs(); + + $rectorKernel = new RectorKernel(); + return $rectorKernel->createFromConfigs($configFiles); + } } diff --git a/src/Exception/Application/FileProcessingException.php b/src/Exception/Application/FileProcessingException.php deleted file mode 100644 index a0edf8c50a0..00000000000 --- a/src/Exception/Application/FileProcessingException.php +++ /dev/null @@ -1,24 +0,0 @@ -getRealPath(), - PHP_EOL . PHP_EOL, - $throwable - ); - - parent::__construct($message); - } -} diff --git a/src/Exception/InvalidNodeTypeException.php b/src/Exception/InvalidNodeTypeException.php deleted file mode 100644 index 21fc0799b44..00000000000 --- a/src/Exception/InvalidNodeTypeException.php +++ /dev/null @@ -1,11 +0,0 @@ - $properties - * @param string|null $parent fully qualified name of parent class - * @param string[] $traits list of fully qualified names of traits used in class - */ - public function createNode( - string $fullyQualifiedName, - array $properties, - ?string $parent = null, - array $traits = [] - ): Namespace_ | Class_ { - $namespaceParts = explode('\\', ltrim($fullyQualifiedName, '\\')); - $className = array_pop($namespaceParts); - $namespace = implode('\\', $namespaceParts); - - $namespaceBuilder = null; - if ($namespace !== '') { - $namespaceBuilder = new NamespaceBuilder($namespace); - } - - $classBuilder = new ClassBuilder($className); - if ($parent !== null && $parent !== '') { - $classBuilder->extend($this->fixFullyQualifiedName($parent)); - } - - foreach ($traits as $trait) { - $classBuilder->addStmt(new TraitUseBuilder($this->fixFullyQualifiedName($trait))); - } - - foreach ($properties as $propertyName => $propertySettings) { - $propertyType = $propertySettings['type']; - $nullable = $propertySettings['nullable'] ?? false; - if ($nullable) { - $propertyType = new NullableType($propertyType); - } - - $propertyBuilder = new PropertyBuilder($propertyName); - $propertyBuilder->setType($propertyType); - $classBuilder->addStmt($propertyBuilder); - } - - if ($namespaceBuilder !== null) { - $namespaceBuilder->addStmt($classBuilder); - return $namespaceBuilder->getNode(); - } - - return $classBuilder->getNode(); - } - - private function fixFullyQualifiedName(string $fullyQualifiedName): string - { - return '\\' . ltrim($fullyQualifiedName, '\\'); - } -} diff --git a/src/PhpParser/Parser/NikicPhpParserFactory.php b/src/PhpParser/Parser/NikicPhpParserFactory.php deleted file mode 100644 index c8b1bf75485..00000000000 --- a/src/PhpParser/Parser/NikicPhpParserFactory.php +++ /dev/null @@ -1,28 +0,0 @@ -parserFactory->create(ParserFactory::PREFER_PHP7, $this->lexer, [ - 'useIdentifierNodes' => true, - 'useConsistentVariableNodes' => true, - 'useExpressionStatements' => true, - 'useNopStatements' => false, - ]); - } -} diff --git a/tests/NodeFactory/ClassWithPublicPropertiesFactory/ClassWithPublicPropertiesFactoryTest.php b/tests/NodeFactory/ClassWithPublicPropertiesFactory/ClassWithPublicPropertiesFactoryTest.php deleted file mode 100644 index 320aafae0fe..00000000000 --- a/tests/NodeFactory/ClassWithPublicPropertiesFactory/ClassWithPublicPropertiesFactoryTest.php +++ /dev/null @@ -1,61 +0,0 @@ -bootFromConfigFiles([__DIR__ . '/../../../config/config.php']); - $this->classWithPublicPropertiesFactory = $this->getService(ClassWithPublicPropertiesFactory::class); - $this->betterStandardPrinter = $this->getService(BetterStandardPrinter::class); - } - - /** - * @dataProvider provideData() - */ - public function test(SmartFileInfo $fixtureFileInfo): void - { - $contents = $fixtureFileInfo->getContents(); - // normalize for windows compat - $contents = str_replace("\r\n", "\n", $contents); - [$content, $expected] = explode("-----\n", $contents, 2); - - $classSettings = Json::decode($content, Json::FORCE_ARRAY); - - $node = $this->classWithPublicPropertiesFactory->createNode( - $classSettings['fullyQualifiedName'], - $classSettings['properties'], - $classSettings['parent'] ?? null, - $classSettings['traits'] ?? [] - ); - - $output = "betterStandardPrinter->print($node) . "\n"; - $this->assertSame($expected, $output); - } - - /** - * @return Iterator - */ - public function provideData(): Iterator - { - return StaticFixtureFinder::yieldDirectoryExclusively(__DIR__ . '/Fixture'); - } -} diff --git a/tests/NodeFactory/ClassWithPublicPropertiesFactory/Fixture/empty_class_no_namespace.php.inc b/tests/NodeFactory/ClassWithPublicPropertiesFactory/Fixture/empty_class_no_namespace.php.inc deleted file mode 100644 index 6a9097efca6..00000000000 --- a/tests/NodeFactory/ClassWithPublicPropertiesFactory/Fixture/empty_class_no_namespace.php.inc +++ /dev/null @@ -1,12 +0,0 @@ -{ - "fullyQualifiedName": "EmptyClassNoNamespace", - "properties": [], - "parent": null, - "traits": [] -} ------ -