Skip to content

Commit

Permalink
Make use of RenameClassNonPhpRector (#4124)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Jun 8, 2023
1 parent d003424 commit e012a3e
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 101 deletions.
12 changes: 0 additions & 12 deletions easy-ci.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
use Rector\ReadWrite\Contract\ParentNodeReadAnalyzerInterface;
use Rector\ReadWrite\Contract\ReadNodeAnalyzerInterface;
use Rector\Set\Contract\SetListInterface;
use Rector\Skipper\Contract\SkipVoterInterface;
use Rector\StaticTypeMapper\Contract\PhpDocParser\PhpDocTypeMapperInterface;
use Rector\StaticTypeMapper\Contract\PhpParser\PhpParserNodeMapperInterface;
use Rector\Testing\PHPUnit\AbstractTestCase;
Expand All @@ -40,7 +39,6 @@

return static function (EasyCIConfig $easyCiConfig): void {
$easyCiConfig->typesToSkip([
SkipVoterInterface::class,
AttributeDecoratorInterface::class,
ArrayItemNode::class,
PhpDocNodeDecoratorInterface::class,
Expand Down Expand Up @@ -75,16 +73,6 @@
ParentNodeReadAnalyzerInterface::class,
StmtsAwareInterface::class,
NodeTypeGroup::class,
// deprecated, keep it for now
TemplateResolverInterface::class,

MethodTypeAnalyzer::class,
DoctrineAnnotationFactory::class,
ClassFromEnumFactory::class,
CoalesceAnalyzer::class,
NamespacedNameDecorator::class,
NamedVariableFactory::class,
BinaryOpTreeRootLocator::class,

ScopeResolverNodeVisitorInterface::class,
]);
Expand Down
10 changes: 8 additions & 2 deletions packages/ReadWrite/NodeAnalyzer/ReadExprAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,21 @@
use PhpParser\Node\Expr;
use Rector\Core\Exception\NotImplementedYetException;
use Rector\ReadWrite\Contract\ReadNodeAnalyzerInterface;
use Rector\ReadWrite\ReadNodeAnalyzer\LocalPropertyFetchReadNodeAnalyzer;
use Rector\ReadWrite\ReadNodeAnalyzer\VariableReadNodeAnalyzer;

final class ReadExprAnalyzer
{
/**
* @param ReadNodeAnalyzerInterface[] $readNodeAnalyzers
* @var ReadNodeAnalyzerInterface[]
*/
private array $readNodeAnalyzers = [];

public function __construct(
private readonly array $readNodeAnalyzers
VariableReadNodeAnalyzer $variableReadNodeAnalyzer,
LocalPropertyFetchReadNodeAnalyzer $localPropertyFetchReadNodeAnalyzer,
) {
$this->readNodeAnalyzers = [$variableReadNodeAnalyzer, $localPropertyFetchReadNodeAnalyzer];
}

/**
Expand Down
12 changes: 8 additions & 4 deletions packages/Skipper/Skipper/Skipper.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
namespace Rector\Skipper\Skipper;

use Rector\Skipper\Contract\SkipVoterInterface;
use Rector\Skipper\SkipVoter\ClassSkipVoter;
use Rector\Skipper\SkipVoter\PathSkipVoter;

/**
* @api
Expand All @@ -18,11 +20,13 @@ final class Skipper
private const FILE_ELEMENT = 'file_elements';

/**
* @param SkipVoterInterface[] $skipVoters
* @var SkipVoterInterface[]
*/
public function __construct(
private readonly array $skipVoters
) {
private array $skipVoters = [];

public function __construct(ClassSkipVoter $classSkipVoter, PathSkipVoter $pathSkipVoter)
{
$this->skipVoters = [$classSkipVoter, $pathSkipVoter];
}

public function shouldSkipElement(string | object $element): bool
Expand Down
30 changes: 27 additions & 3 deletions rules/Naming/PropertyRenamer/MatchTypePropertyRenamer.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@
namespace Rector\Naming\PropertyRenamer;

use PhpParser\Node\Stmt\Property;
use PhpParser\Node\VarLikeIdentifier;
use Rector\Naming\Guard\PropertyConflictingNameGuard\MatchPropertyTypeConflictingNameGuard;
use Rector\Naming\RenameGuard\PropertyRenameGuard;
use Rector\Naming\ValueObject\PropertyRename;

final class MatchTypePropertyRenamer
{
public function __construct(
private readonly PropertyRenamer $propertyRenamer,
private readonly MatchPropertyTypeConflictingNameGuard $matchPropertyTypeConflictingNameGuard
private readonly MatchPropertyTypeConflictingNameGuard $matchPropertyTypeConflictingNameGuard,
private readonly PropertyRenameGuard $propertyRenameGuard,
private readonly PropertyFetchRenamer $propertyFetchRenamer,
) {
}

Expand All @@ -22,6 +25,27 @@ public function rename(PropertyRename $propertyRename): ?Property
return null;
}

return $this->propertyRenamer->rename($propertyRename);
if ($propertyRename->isAlreadyExpectedName()) {
return null;
}

if ($this->propertyRenameGuard->shouldSkip($propertyRename)) {
return null;
}

$onlyPropertyProperty = $propertyRename->getPropertyProperty();
$onlyPropertyProperty->name = new VarLikeIdentifier($propertyRename->getExpectedName());
$this->renamePropertyFetchesInClass($propertyRename);

return $propertyRename->getProperty();
}

private function renamePropertyFetchesInClass(PropertyRename $propertyRename): void
{
$this->propertyFetchRenamer->renamePropertyFetchesInClass(
$propertyRename->getClassLike(),
$propertyRename->getCurrentName(),
$propertyRename->getExpectedName()
);
}
}
45 changes: 0 additions & 45 deletions rules/Naming/PropertyRenamer/PropertyRenamer.php

This file was deleted.

34 changes: 0 additions & 34 deletions src/Console/Command/InitCommand.php

This file was deleted.

2 changes: 1 addition & 1 deletion src/Kernel/RectorKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ final class RectorKernel
/**
* @var string
*/
private const CACHE_KEY = 'v73';
private const CACHE_KEY = 'v74';

private ContainerInterface|null $container = null;

Expand Down

0 comments on commit e012a3e

Please sign in to comment.