diff --git a/.github/workflows/code_analysis.yaml b/.github/workflows/code_analysis.yaml index c8faf383fc0..b1b94385adc 100644 --- a/.github/workflows/code_analysis.yaml +++ b/.github/workflows/code_analysis.yaml @@ -47,7 +47,6 @@ jobs: vendor/bin/class-leak check bin config src rules packages \ --skip-type="Rector\\NodeTypeResolver\\PHPStan\\Scope\\Contract\\NodeVisitor\\ScopeResolverNodeVisitorInterface" \ --skip-type="Rector\\BetterPhpDocParser\\Contract\\BasePhpDocNodeVisitorInterface" \ - --skip-type="Rector\\Core\\Contract\\Processor\\FileProcessorInterface" \ --skip-type="Rector\\BetterPhpDocParser\\Contract\\PhpDocParser\\PhpDocNodeDecoratorInterface" \ --skip-type="Rector\\BetterPhpDocParser\\ValueObject\\Type\\FullyQualifiedIdentifierTypeNode" diff --git a/phpstan.neon b/phpstan.neon index f089c9e6355..f39ec55eb37 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -24,6 +24,7 @@ parameters: paths: - rector.php - bin + - config - src - rules - packages @@ -33,8 +34,6 @@ parameters: - rules-tests - utils - utils-tests - # this cannot be put it, because it wipes PHPStan cache on each run :( - must run in separate - #- config scanDirectories: - stubs @@ -90,11 +89,6 @@ parameters: message: '#Access to an undefined property PhpParser\\Node\\Expr\:\:\$expr#' path: rules/DeadCode/NodeManipulator/LivingCodeManipulator.php - # 3rd party package - - - message: '#Array (with keys|destruct) is not allowed\. Use value object to pass data instead#' - path: rules/Php70/EregToPcreTransformer.php - # lack of generic array in nikic/php-parser - '#Method (.*?) should return array but returns array#' @@ -107,12 +101,6 @@ parameters: - '#Method (.*?) should return (.*?)\|null but returns PhpParser\\Node\|null#' - '#Method (.*?) should return array but returns array#' - - - message: '#\$this as argument is not allowed\. Refactor method to service composition#' - paths: - - src/Rector/AbstractRector.php - - src/PhpParser/AstResolver.php - - '#Property Rector\\Core\\PhpParser\\Node\\AssignAndBinaryMap\:\:\$binaryOpToAssignClasses \(array, class\-string\>\) does not accept array#' - @@ -134,11 +122,6 @@ parameters: - packages/PhpDocParser/PhpDocParser/PhpDocNodeTraverser.php - rules/Php70/EregToPcreTransformer.php - - - message: '#\$this as argument is not allowed\. Refactor method to service composition#' - paths: - - packages/BetterPhpDocParser/ValueObject/Parser/BetterTokenIterator.php - - '#Cognitive complexity for "Rector\\BetterPhpDocParser\\PhpDocParser\\DoctrineAnnotationDecorator\:\:mergeNestedDoctrineAnnotations\(\)" is \d+, keep it under 11#' - '#Cognitive complexity for "Rector\\NodeTypeResolver\\NodeTypeResolver\:\:getType\(\)" is \d+, keep it under 11#' @@ -275,10 +258,6 @@ parameters: - '#Callable callable\(PHPStan\\Type\\Type\)\: PHPStan\\Type\\Type invoked with 2 parameters, 1 required#' - - - message: '#Make callable type explicit#' - path: src/NodeManipulator/BinaryOpManipulator.php - # stmts refactoring - '#Cognitive complexity for "Rector\\DeadCode\\Rector\\Assign\\RemoveDoubleAssignRector\:\:refactorWithScope\(\)" is \d+, keep it under 11#' @@ -433,11 +412,6 @@ parameters: message: '#Function "(.*?)\(\)" cannot be used/left in the code#' path: src/Util/Reflection/PrivatesAccessor.php - # for reflection - - - message: '#\$this as argument is not allowed\. Refactor method to service composition#' - path: packages/BetterPhpDocParser/PhpDocParser/BetterPhpDocParser.php - - message: '#Offset \(int\|string\) on array in isset\(\) always exists and is not nullable#' path: packages/BetterPhpDocParser/PhpDocParser/DoctrineAnnotationDecorator.php @@ -446,10 +420,6 @@ parameters: message: '#Method Rector\\Core\\Util\\ArrayParametersMerger\:\:mergeLeftToRightWithCallable\(\) has parameter \$mergeCallback with no signature specified for callable#' path: src/Util/ArrayParametersMerger.php - - - message: '#Make callable type explicit\. Here is how\: https\://phpstan\.org/writing\-php\-code/phpdoc\-types\#callables#' - path: src/Util/ArrayParametersMerger.php - # fixture class - '#Class "Rector\\Core\\Tests\\Issues\\ScopeNotAvailable\\Variable\\ArrayItemForeachValueRector" is missing @see annotation with test case class reference#' @@ -513,9 +483,6 @@ parameters: # useless - '#Parameter \#1 \$suffix of method PHPUnit\\Framework\\Assert\:\:assertStringEndsWith\(\) expects non\-empty\-string, string given#' - # reported in configs - - '#Symfony\\Component\\DependencyInjection\\Loader\\Configurator\\service not found#' - - message: '#Function "function_exists\(\)" cannot be used/left in the code#' path: src/functions/node_helper.php @@ -532,11 +499,6 @@ parameters: - '#Call to deprecated method getDirectClassNames\(\) of class PHPStan\\Type\\TypeUtils.*#' - '#Parameter 3 should use "PHPStan\\Reflection\\ParameterReflectionWithPhpDocs" type as the only type passed to this method#' - # actually used in global scope - - - message: '#Anonymous function has an unused use \$container#' - path: src/Autoloading/BootstrapFilesIncluder.php - # false positive on enums - '#Method Rector\\Core\\Console\\Command\\SetupCICommand\:\:resolveCurrentCI\(\) never returns (.*?) so it can be removed from the return type#' @@ -559,9 +521,6 @@ parameters: - '#Access to an undefined property PhpParser\\Node\\Stmt\\ClassLike\|PhpParser\\Node\\Stmt\\Declare_\|Rector\\Core\\Contract\\PhpParser\\Node\\StmtsAwareInterface\:\:\$stmts#' - '#Access to an undefined property \(PhpParser\\Node\\Stmt&Rector\\Core\\Contract\\PhpParser\\Node\\StmtsAwareInterface\)\|PhpParser\\Node\\Stmt\\ClassLike\|PhpParser\\Node\\Stmt\\Declare_\:\:\$stmts#' - # WIP - - '#Return type \(int\|PhpParser\\Node\\Expr\\FuncCall\|PhpParser\\Node\\Expr\\Ternary\|null\) of method Rector\\Php71\\Rector\\FuncCall\\CountOnNullRector\:\:refactorWithScope\(\) should be covariant with return type \(1\|2\|3\|4\|array\|PhpParser\\Node\|null\) of method Rector\\Core\\Contract\\Rector\\ScopeAwarePhpRectorInterface\:\:refactorWithScope\(\)#' - # looks like a bug in the PHPStan rule, see https://github.com/rectorphp/rector-src/pull/3645#issuecomment-1561294527 - message: '#Method name "(get|has|set)Attribute\(\)" is used in multiple traits\. Make it unique to avoid conflicts#' @@ -638,10 +597,6 @@ parameters: message: '#Fetching class constant class of deprecated class Rector\\Core\\Contract\\Rector\\NonPhpRectorInterface#' path: packages/Config/* - - - message: '#Make callable type explicit\. Here is how\: https\://phpstan\.org/writing\-php\-code/phpdoc\-types\#callables#' - path: packages/Config/RectorConfig.php - # method signature kept for symmetry of hasParentClassMethod() with getParentClassMethod() - message: '#Parameters should use "PhpParser\\Node\\Stmt\\ClassMethod" types as the only types passed to this method#' @@ -651,7 +606,3 @@ parameters: - message: '#Function "(class_exists|interface_exists)\(\)" cannot be used/left in the code\: use ReflectionProvider\->has\*\(\) instead#' path: packages/Skipper/SkipCriteriaResolver/SkippedClassResolver.php - - # deprecated, remove later - - '#deprecated (interface|class) Rector\\Core\\Contract\\Processor\\FileProcessorInterface#' - - '#Call to deprecated method processWithFileProcessors\(\) of class Rector\\Core\\Application\\ApplicationFileProcessor#' diff --git a/src/Application/ApplicationFileProcessor.php b/src/Application/ApplicationFileProcessor.php index 3c1a88c472b..05272290efe 100644 --- a/src/Application/ApplicationFileProcessor.php +++ b/src/Application/ApplicationFileProcessor.php @@ -9,7 +9,6 @@ use Rector\Core\Application\FileProcessor\PhpFileProcessor; use Rector\Core\Configuration\Option; use Rector\Core\Configuration\Parameter\SimpleParameterProvider; -use Rector\Core\Contract\Processor\FileProcessorInterface; use Rector\Core\Provider\CurrentFileProvider; use Rector\Core\Util\ArrayParametersMerger; use Rector\Core\ValueObject\Application\File; @@ -26,7 +25,6 @@ use Symplify\EasyParallel\Exception\ParallelShouldNotHappenException; use Symplify\EasyParallel\ScheduleFactory; use Throwable; -use Webmozart\Assert\Assert; final class ApplicationFileProcessor { @@ -40,9 +38,6 @@ final class ApplicationFileProcessor */ private array $systemErrors = []; - /** - * @param FileProcessorInterface[] $fileProcessors - */ public function __construct( private readonly SymfonyStyle $symfonyStyle, private readonly FileFactory $fileFactory, @@ -53,28 +48,7 @@ public function __construct( private readonly ChangedFilesDetector $changedFilesDetector, private readonly CurrentFileProvider $currentFileProvider, private readonly PhpFileProcessor $phpFileProcessor, - private readonly array $fileProcessors, ) { - $fileProcessorClasses = []; - - foreach ($this->fileProcessors as $fileProcessor) { - trigger_error( - sprintf( - 'Rector will support only PHP, as that is the only code the AST can handle.%sThe custom "%s" file processor will not be supported, and should be refactored into own tool with file finder/printer.', - PHP_EOL, - $fileProcessor::class - ) . PHP_EOL . PHP_EOL, - E_USER_WARNING - ); - // to notice - sleep(2); - } - - foreach ($fileProcessors as $fileProcessor) { - $fileProcessorClasses[] = $fileProcessor::class; - } - - Assert::uniqueValues($fileProcessorClasses); } /** @@ -164,18 +138,8 @@ private function processFile(File $file, array $systemErrorsAndFileDiffs, Config { $this->currentFileProvider->setFile($file); - // BC layer, soon the file processors will be removed - $otherSystemErrorsAndFileDiffs = $this->processWithFileProcessors( - $file, - $configuration, - $systemErrorsAndFileDiffs - ); - $systemErrorsAndFileDiffs = $this->arrayParametersMerger->merge( - $systemErrorsAndFileDiffs, - $otherSystemErrorsAndFileDiffs - ); - $phpSystemErrorsAndFileDiffs = $this->phpFileProcessor->process($file, $configuration); + $systemErrorsAndFileDiffs = $this->arrayParametersMerger->merge( $systemErrorsAndFileDiffs, $phpSystemErrorsAndFileDiffs @@ -292,27 +256,4 @@ private function resolveCalledRectorBinary(): ?string return $potentialEcsBinaryPath; } - - /** - * @deprecated Custom file processors are deprecated. Use custom tool instead. - * - * @param array{system_errors: SystemError[], file_diffs: FileDiff[], system_errors_count: int} $systemErrorsAndFileDiffs - * @return array{system_errors: SystemError[], file_diffs: FileDiff[], system_errors_count: int} - */ - private function processWithFileProcessors( - File $file, - Configuration $configuration, - array $systemErrorsAndFileDiffs - ): mixed { - foreach ($this->fileProcessors as $fileProcessor) { - if (! $fileProcessor->supports($file, $configuration)) { - continue; - } - - $result = $fileProcessor->process($file, $configuration); - $systemErrorsAndFileDiffs = $this->arrayParametersMerger->merge($systemErrorsAndFileDiffs, $result); - } - - return $systemErrorsAndFileDiffs; - } } diff --git a/src/Contract/Processor/FileProcessorInterface.php b/src/Contract/Processor/FileProcessorInterface.php deleted file mode 100644 index cb2e862c7e8..00000000000 --- a/src/Contract/Processor/FileProcessorInterface.php +++ /dev/null @@ -1,30 +0,0 @@ -alias(TypeParser::class, BetterTypeParser::class); - $rectorConfig->when(ApplicationFileProcessor::class) - ->needs('$fileProcessors') - ->giveTagged(FileProcessorInterface::class); - - $rectorConfig->when(FileFactory::class) - ->needs('$fileProcessors') - ->giveTagged(FileProcessorInterface::class); - $rectorConfig->when(RectorNodeTraverser::class) ->needs('$rectors') ->giveTagged(RectorInterface::class); diff --git a/src/ValueObjectFactory/Application/FileFactory.php b/src/ValueObjectFactory/Application/FileFactory.php index f8e903b1735..d8ceb4cdeaf 100644 --- a/src/ValueObjectFactory/Application/FileFactory.php +++ b/src/ValueObjectFactory/Application/FileFactory.php @@ -5,7 +5,6 @@ namespace Rector\Core\ValueObjectFactory\Application; use Rector\Caching\Detector\ChangedFilesDetector; -use Rector\Core\Contract\Processor\FileProcessorInterface; use Rector\Core\FileSystem\FilesFinder; use Rector\Core\ValueObject\Configuration; @@ -14,13 +13,9 @@ */ final class FileFactory { - /** - * @param FileProcessorInterface[] $fileProcessors - */ public function __construct( private readonly FilesFinder $filesFinder, private readonly ChangedFilesDetector $changedFilesDetector, - private readonly iterable $fileProcessors ) { } @@ -34,7 +29,7 @@ public function findFilesInPaths(array $paths, Configuration $configuration): ar $this->changedFilesDetector->clear(); } - $supportedFileExtensions = $this->resolveSupportedFileExtensions($configuration); + $supportedFileExtensions = $configuration->getFileExtensions(); $filePaths = $this->filesFinder->findInDirectoriesAndFiles($paths, $supportedFileExtensions); $fileExtensions = $configuration->getFileExtensions(); @@ -45,24 +40,4 @@ public function findFilesInPaths(array $paths, Configuration $configuration): ar return array_filter($filePaths, $fileWithExtensionsFilter); } - - /** - * @return string[] - */ - private function resolveSupportedFileExtensions(Configuration $configuration): array - { - $supportedFileExtensions = []; - - foreach ($this->fileProcessors as $fileProcessor) { - $supportedFileExtensions = array_merge( - $supportedFileExtensions, - $fileProcessor->getSupportedFileExtensions() - ); - } - - // basic PHP extensions - $supportedFileExtensions = array_merge($supportedFileExtensions, $configuration->getFileExtensions()); - - return array_unique($supportedFileExtensions); - } }