Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DX] Remove undocumented and single implementer of skip voter, keep it simple #6275

Merged
merged 1 commit into from
Sep 2, 2024
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
2 changes: 1 addition & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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
-
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
*/
public function __construct(
private iterable $classNameImportSkipVoters,
private UseImportsResolver $useImportsResolver
private UseImportsResolver $useImportsResolver,
) {
}

Expand Down
13 changes: 0 additions & 13 deletions src/DependencyInjection/LazyContainerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -366,11 +364,6 @@ final class LazyContainerFactory
ExprNodeMapper::class,
];

/**
* @var array<class-string<SkipVoterInterface>>
*/
private const SKIP_VOTER_CLASSES = [ClassSkipVoter::class];

/**
* @var array<class-string<ConverterAttributeDecoratorInterface>>
*/
Expand Down Expand Up @@ -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);
Expand Down
15 changes: 0 additions & 15 deletions src/Skipper/Contract/SkipVoterInterface.php

This file was deleted.

3 changes: 1 addition & 2 deletions src/Skipper/SkipVoter/ClassSkipVoter.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
namespace Rector\Skipper\SkipVoter;

use PHPStan\Reflection\ReflectionProvider;
use Rector\Skipper\Contract\SkipVoterInterface;
use Rector\Skipper\SkipCriteriaResolver\SkippedClassResolver;
use Rector\Skipper\Skipper\SkipSkipper;

final readonly class ClassSkipVoter implements SkipVoterInterface
final readonly class ClassSkipVoter
{
public function __construct(
private SkipSkipper $skipSkipper,
Expand Down
25 changes: 6 additions & 19 deletions src/Skipper/Skipper/Skipper.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,19 @@
use PhpParser\Node;
use Rector\Contract\Rector\RectorInterface;
use Rector\ProcessAnalyzer\RectifiedAnalyzer;
use Rector\Skipper\Contract\SkipVoterInterface;
use Webmozart\Assert\Assert;
use Rector\Skipper\SkipVoter\ClassSkipVoter;

/**
* @api
* @see \Rector\Tests\Skipper\Skipper\SkipperTest
*/
final readonly class Skipper
{
/**
* @param array<SkipVoterInterface> $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
Expand All @@ -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);
}

/**
Expand Down