-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #241 from palantirnet/feature/static-argument-rena…
…me-rector StaticArgumentRenameBase and DrupalServiceRenameBase are now covered with StaticArgumentRenameRector
- Loading branch information
Showing
10 changed files
with
112 additions
and
281 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?php | ||
|
||
namespace DrupalRector\Rector\Deprecation; | ||
|
||
use DrupalRector\Rector\ValueObject\DrupalServiceRenameConfiguration; | ||
use PhpParser\Node; | ||
use Rector\Core\Contract\Rector\ConfigurableRectorInterface; | ||
use Rector\Core\Rector\AbstractRector; | ||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample; | ||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; | ||
|
||
class DrupalServiceRenameRector extends AbstractRector implements ConfigurableRectorInterface { | ||
|
||
/** | ||
* @var DrupalServiceRenameConfiguration[] $staticArgumentRenameConfigs | ||
*/ | ||
protected array $staticArgumentRenameConfigs = []; | ||
|
||
public function configure(array $configuration): void { | ||
foreach ($configuration as $value) { | ||
if (!($value instanceof DrupalServiceRenameConfiguration)) { | ||
throw new \InvalidArgumentException(sprintf( | ||
'Each configuration item must be an instance of "%s"', | ||
DrupalServiceRenameConfiguration::class | ||
)); | ||
} | ||
} | ||
|
||
$this->staticArgumentRenameConfigs = $configuration; | ||
} | ||
|
||
public function getNodeTypes(): array { | ||
return [ | ||
Node\Expr\StaticCall::class, | ||
]; | ||
} | ||
|
||
public function refactor(Node $node) { | ||
if ($node instanceof Node\Expr\StaticCall) { | ||
foreach ($this->staticArgumentRenameConfigs as $configuration) { | ||
if ($this->getName($node->name) === 'service' && (string) $node->class === 'Drupal') { | ||
if (count($node->args) === 1) { | ||
/* @var Node\Arg $argument */ | ||
$argument = $node->args[0]; | ||
|
||
if ($argument->value instanceof Node\Scalar\String_ && $argument->value->value === $configuration->getDeprecatedService()) { | ||
$node->args[0] = new Node\Arg(new Node\Scalar\String_($configuration->getNewService())); | ||
|
||
return $node; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
return NULL; | ||
} | ||
|
||
public function getRuleDefinition(): RuleDefinition { | ||
return new RuleDefinition('Renames the IDs in Drupal::service() calls', [ | ||
new ConfiguredCodeSample( | ||
<<<'CODE_BEFORE' | ||
\Drupal::service('old')->foo(); | ||
CODE_BEFORE | ||
, | ||
<<<'CODE_AFTER' | ||
\Drupal::service('bar')->foo(); | ||
CODE_AFTER | ||
, | ||
[ | ||
new DrupalServiceRenameConfiguration( | ||
'old', | ||
'bar', | ||
) | ||
] | ||
), | ||
]); | ||
} | ||
|
||
} |
30 changes: 0 additions & 30 deletions
30
src/Rector/Deprecation/PathAliasManagerServiceNameRector.php
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
30 changes: 0 additions & 30 deletions
30
src/Rector/Deprecation/PathAliasWhitelistServiceNameRector.php
This file was deleted.
Oops, something went wrong.
30 changes: 0 additions & 30 deletions
30
src/Rector/Deprecation/PathProcessorAliasServiceNameRector.php
This file was deleted.
Oops, something went wrong.
30 changes: 0 additions & 30 deletions
30
src/Rector/Deprecation/PathSubscriberServiceNameRector.php
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.