Skip to content

Commit a957503

Browse files
authored
[DX] Remove undocumented and single implementer of skip voter, keep it simple (#6275)
1 parent 0c37a47 commit a957503

File tree

6 files changed

+9
-51
lines changed

6 files changed

+9
-51
lines changed

phpstan.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ parameters:
271271
# marker interface
272272
- src/Contract/PhpParser/Node/StmtsAwareInterface.php
273273
# designed for extension
274-
- src/Skipper/Contract/SkipVoterInterface.php
274+
#- src/Skipper/Contract/SkipVoterInterface.php
275275

276276
# generated class in /vendor
277277
-

rules/CodingStyle/ClassNameImport/ClassNameImportSkipper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*/
2727
public function __construct(
2828
private iterable $classNameImportSkipVoters,
29-
private UseImportsResolver $useImportsResolver
29+
private UseImportsResolver $useImportsResolver,
3030
) {
3131
}
3232

src/DependencyInjection/LazyContainerFactory.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,7 @@
162162
use Rector\PHPStanStaticTypeMapper\TypeMapper\VoidTypeMapper;
163163
use Rector\PostRector\Application\PostFileProcessor;
164164
use Rector\Rector\AbstractRector;
165-
use Rector\Skipper\Contract\SkipVoterInterface;
166165
use Rector\Skipper\Skipper\Skipper;
167-
use Rector\Skipper\SkipVoter\ClassSkipVoter;
168166
use Rector\StaticTypeMapper\Contract\PhpDocParser\PhpDocTypeMapperInterface;
169167
use Rector\StaticTypeMapper\Contract\PhpParser\PhpParserNodeMapperInterface;
170168
use Rector\StaticTypeMapper\Mapper\PhpParserNodeMapper;
@@ -366,11 +364,6 @@ final class LazyContainerFactory
366364
ExprNodeMapper::class,
367365
];
368366

369-
/**
370-
* @var array<class-string<SkipVoterInterface>>
371-
*/
372-
private const SKIP_VOTER_CLASSES = [ClassSkipVoter::class];
373-
374367
/**
375368
* @var array<class-string<ConverterAttributeDecoratorInterface>>
376369
*/
@@ -531,12 +524,6 @@ static function (UnionTypeMapper $unionTypeMapper, Container $container): void {
531524
->needs('$nodeNameResolvers')
532525
->giveTagged(NodeNameResolverInterface::class);
533526

534-
$rectorConfig->when(Skipper::class)
535-
->needs('$skipVoters')
536-
->giveTagged(SkipVoterInterface::class);
537-
538-
$this->registerTagged($rectorConfig, self::SKIP_VOTER_CLASSES, SkipVoterInterface::class);
539-
540527
$rectorConfig->when(AttributeGroupNamedArgumentManipulator::class)
541528
->needs('$converterAttributeDecorators')
542529
->giveTagged(ConverterAttributeDecoratorInterface::class);

src/Skipper/Contract/SkipVoterInterface.php

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/Skipper/SkipVoter/ClassSkipVoter.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@
55
namespace Rector\Skipper\SkipVoter;
66

77
use PHPStan\Reflection\ReflectionProvider;
8-
use Rector\Skipper\Contract\SkipVoterInterface;
98
use Rector\Skipper\SkipCriteriaResolver\SkippedClassResolver;
109
use Rector\Skipper\Skipper\SkipSkipper;
1110

12-
final readonly class ClassSkipVoter implements SkipVoterInterface
11+
final readonly class ClassSkipVoter
1312
{
1413
public function __construct(
1514
private SkipSkipper $skipSkipper,

src/Skipper/Skipper/Skipper.php

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,19 @@
77
use PhpParser\Node;
88
use Rector\Contract\Rector\RectorInterface;
99
use Rector\ProcessAnalyzer\RectifiedAnalyzer;
10-
use Rector\Skipper\Contract\SkipVoterInterface;
11-
use Webmozart\Assert\Assert;
10+
use Rector\Skipper\SkipVoter\ClassSkipVoter;
1211

1312
/**
1413
* @api
1514
* @see \Rector\Tests\Skipper\Skipper\SkipperTest
1615
*/
1716
final readonly class Skipper
1817
{
19-
/**
20-
* @param array<SkipVoterInterface> $skipVoters
21-
*/
2218
public function __construct(
2319
private RectifiedAnalyzer $rectifiedAnalyzer,
24-
private array $skipVoters,
25-
private PathSkipper $pathSkipper
20+
private PathSkipper $pathSkipper,
21+
private ClassSkipVoter $classSkipVoter,
2622
) {
27-
Assert::allIsInstanceOf($this->skipVoters, SkipVoterInterface::class);
2823
}
2924

3025
public function shouldSkipElement(string | object $element): bool
@@ -39,19 +34,11 @@ public function shouldSkipFilePath(string $filePath): bool
3934

4035
public function shouldSkipElementAndFilePath(string | object $element, string $filePath): bool
4136
{
42-
foreach ($this->skipVoters as $skipVoter) {
43-
if (! $skipVoter->match($element)) {
44-
continue;
45-
}
46-
47-
if (! $skipVoter->shouldSkip($element, $filePath)) {
48-
continue;
49-
}
50-
51-
return true;
37+
if (! $this->classSkipVoter->match($element)) {
38+
return false;
5239
}
5340

54-
return false;
41+
return $this->classSkipVoter->shouldSkip($element, $filePath);
5542
}
5643

5744
/**

0 commit comments

Comments
 (0)