From a9575034c3c774fe8aa5c42a0adbea008efaf000 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Mon, 2 Sep 2024 01:39:38 +0100 Subject: [PATCH] [DX] Remove undocumented and single implementer of skip voter, keep it simple (#6275) --- phpstan.neon | 2 +- .../ClassNameImportSkipper.php | 2 +- .../LazyContainerFactory.php | 13 ---------- src/Skipper/Contract/SkipVoterInterface.php | 15 ----------- src/Skipper/SkipVoter/ClassSkipVoter.php | 3 +-- src/Skipper/Skipper/Skipper.php | 25 +++++-------------- 6 files changed, 9 insertions(+), 51 deletions(-) delete mode 100644 src/Skipper/Contract/SkipVoterInterface.php diff --git a/phpstan.neon b/phpstan.neon index dd95e7ef39d..d4659706e2d 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -271,7 +271,7 @@ parameters: # marker interface - src/Contract/PhpParser/Node/StmtsAwareInterface.php # designed for extension - - src/Skipper/Contract/SkipVoterInterface.php + #- src/Skipper/Contract/SkipVoterInterface.php # generated class in /vendor - diff --git a/rules/CodingStyle/ClassNameImport/ClassNameImportSkipper.php b/rules/CodingStyle/ClassNameImport/ClassNameImportSkipper.php index a9f746a0369..5d98ddc81d2 100644 --- a/rules/CodingStyle/ClassNameImport/ClassNameImportSkipper.php +++ b/rules/CodingStyle/ClassNameImport/ClassNameImportSkipper.php @@ -26,7 +26,7 @@ */ public function __construct( private iterable $classNameImportSkipVoters, - private UseImportsResolver $useImportsResolver + private UseImportsResolver $useImportsResolver, ) { } diff --git a/src/DependencyInjection/LazyContainerFactory.php b/src/DependencyInjection/LazyContainerFactory.php index aec5d36e12a..2566d34a58e 100644 --- a/src/DependencyInjection/LazyContainerFactory.php +++ b/src/DependencyInjection/LazyContainerFactory.php @@ -162,9 +162,7 @@ use Rector\PHPStanStaticTypeMapper\TypeMapper\VoidTypeMapper; use Rector\PostRector\Application\PostFileProcessor; use Rector\Rector\AbstractRector; -use Rector\Skipper\Contract\SkipVoterInterface; use Rector\Skipper\Skipper\Skipper; -use Rector\Skipper\SkipVoter\ClassSkipVoter; use Rector\StaticTypeMapper\Contract\PhpDocParser\PhpDocTypeMapperInterface; use Rector\StaticTypeMapper\Contract\PhpParser\PhpParserNodeMapperInterface; use Rector\StaticTypeMapper\Mapper\PhpParserNodeMapper; @@ -366,11 +364,6 @@ final class LazyContainerFactory ExprNodeMapper::class, ]; - /** - * @var array> - */ - private const SKIP_VOTER_CLASSES = [ClassSkipVoter::class]; - /** * @var array> */ @@ -531,12 +524,6 @@ static function (UnionTypeMapper $unionTypeMapper, Container $container): void { ->needs('$nodeNameResolvers') ->giveTagged(NodeNameResolverInterface::class); - $rectorConfig->when(Skipper::class) - ->needs('$skipVoters') - ->giveTagged(SkipVoterInterface::class); - - $this->registerTagged($rectorConfig, self::SKIP_VOTER_CLASSES, SkipVoterInterface::class); - $rectorConfig->when(AttributeGroupNamedArgumentManipulator::class) ->needs('$converterAttributeDecorators') ->giveTagged(ConverterAttributeDecoratorInterface::class); diff --git a/src/Skipper/Contract/SkipVoterInterface.php b/src/Skipper/Contract/SkipVoterInterface.php deleted file mode 100644 index 62adba76d67..00000000000 --- a/src/Skipper/Contract/SkipVoterInterface.php +++ /dev/null @@ -1,15 +0,0 @@ - $skipVoters - */ public function __construct( private RectifiedAnalyzer $rectifiedAnalyzer, - private array $skipVoters, - private PathSkipper $pathSkipper + private PathSkipper $pathSkipper, + private ClassSkipVoter $classSkipVoter, ) { - Assert::allIsInstanceOf($this->skipVoters, SkipVoterInterface::class); } public function shouldSkipElement(string | object $element): bool @@ -39,19 +34,11 @@ public function shouldSkipFilePath(string $filePath): bool public function shouldSkipElementAndFilePath(string | object $element, string $filePath): bool { - foreach ($this->skipVoters as $skipVoter) { - if (! $skipVoter->match($element)) { - continue; - } - - if (! $skipVoter->shouldSkip($element, $filePath)) { - continue; - } - - return true; + if (! $this->classSkipVoter->match($element)) { + return false; } - return false; + return $this->classSkipVoter->shouldSkip($element, $filePath); } /**