Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/code_analysis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
51 changes: 1 addition & 50 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ parameters:
paths:
- rector.php
- bin
- config
- src
- rules
- packages
Expand All @@ -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
Expand Down Expand Up @@ -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<PhpParser\\Node\\(.*?)\> but returns array<PhpParser\\Node\>#'

Expand All @@ -107,12 +101,6 @@ parameters:
- '#Method (.*?) should return (.*?)\|null but returns PhpParser\\Node\|null#'
- '#Method (.*?) should return array<T of PhpParser\\Node\> but returns array<PhpParser\\Node\>#'

-
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<PhpParser\\Node\\Expr\\BinaryOp\>, class\-string<PhpParser\\Node\\Expr\\BinaryOp\>\>\) does not accept array#'

-
Expand All @@ -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#'
Expand Down Expand Up @@ -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#'

Expand Down Expand Up @@ -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<PHPStan\\PhpDocParser\\Ast\\PhpDoc\\PhpDocChildNode> in isset\(\) always exists and is not nullable#'
path: packages/BetterPhpDocParser/PhpDocParser/DoctrineAnnotationDecorator.php
Expand All @@ -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#'

Expand Down Expand Up @@ -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
Expand All @@ -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#'

Expand All @@ -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>\|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#'
Expand Down Expand Up @@ -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#'
Expand All @@ -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#'
61 changes: 1 addition & 60 deletions src/Application/ApplicationFileProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,7 +25,6 @@
use Symplify\EasyParallel\Exception\ParallelShouldNotHappenException;
use Symplify\EasyParallel\ScheduleFactory;
use Throwable;
use Webmozart\Assert\Assert;

final class ApplicationFileProcessor
{
Expand All @@ -40,9 +38,6 @@ final class ApplicationFileProcessor
*/
private array $systemErrors = [];

/**
* @param FileProcessorInterface[] $fileProcessors
*/
public function __construct(
private readonly SymfonyStyle $symfonyStyle,
private readonly FileFactory $fileFactory,
Expand All @@ -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);
}

/**
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
}
30 changes: 0 additions & 30 deletions src/Contract/Processor/FileProcessorInterface.php

This file was deleted.

11 changes: 0 additions & 11 deletions src/DependencyInjection/LazyContainerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
use Rector\CodingStyle\ClassNameImport\ClassNameImportSkipVoter\UsesClassNameImportSkipVoter;
use Rector\CodingStyle\Contract\ClassNameImport\ClassNameImportSkipVoterInterface;
use Rector\Config\RectorConfig;
use Rector\Core\Application\ApplicationFileProcessor;
use Rector\Core\Application\ChangedNodeScopeRefresher;
use Rector\Core\Application\FileProcessor\PhpFileProcessor;
use Rector\Core\Configuration\ConfigInitializer;
Expand All @@ -60,7 +59,6 @@
use Rector\Core\Console\Style\RectorStyle;
use Rector\Core\Console\Style\SymfonyStyleFactory;
use Rector\Core\Contract\DependencyInjection\ResetableInterface;
use Rector\Core\Contract\Processor\FileProcessorInterface;
use Rector\Core\Contract\Rector\RectorInterface;
use Rector\Core\DependencyInjection\Laravel\ContainerMemento;
use Rector\Core\Logging\CurrentRectorProvider;
Expand All @@ -74,7 +72,6 @@
use Rector\Core\Provider\CurrentFileProvider;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\Util\Reflection\PrivatesAccessor;
use Rector\Core\ValueObjectFactory\Application\FileFactory;
use Rector\NodeNameResolver\Contract\NodeNameResolverInterface;
use Rector\NodeNameResolver\NodeNameResolver;
use Rector\NodeNameResolver\NodeNameResolver\ClassConstFetchNameResolver;
Expand Down Expand Up @@ -469,14 +466,6 @@ public function create(): RectorConfig

$rectorConfig->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);
Expand Down
27 changes: 1 addition & 26 deletions src/ValueObjectFactory/Application/FileFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
) {
}

Expand All @@ -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();
Expand All @@ -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);
}
}