Skip to content
Merged

cs #918

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
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,4 @@
use Rector\Symfony\Symfony73\Rector\Class_\AuthorizationCheckerToAccessDecisionManagerInVoterRector;

return RectorConfig::configure()
->withRules([
AuthorizationCheckerToAccessDecisionManagerInVoterRector::class,
]);
->withRules([AuthorizationCheckerToAccessDecisionManagerInVoterRector::class]);
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,12 @@ private function matchStringEnvOrParameter(
): void {
$match = Strings::match($argumentValue, '#%env\((?<env>[A-Z_]+)\)#');
if (isset($match['env'])) {
$this->servicesArgumentsByClass[$serviceClassName][self::ENVS][$argumentLocation] = (string) $match['env'];
$this->servicesArgumentsByClass[$serviceClassName][self::ENVS][$argumentLocation] = $match['env'];
}

$match = Strings::match($argumentValue, '#%(?<parameter>[\w]+)%#');
if (isset($match['parameter'])) {
$this->servicesArgumentsByClass[$serviceClassName][self::PARAMETERS][$argumentLocation] = (string) $match['parameter'];
$this->servicesArgumentsByClass[$serviceClassName][self::PARAMETERS][$argumentLocation] = $match['parameter'];
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ public function refactor(Node $node): ?Node
return null;
}

if (! isset($matches[0])) {
return null;
}

$newValue = '@' .
Strings::replace(substr((string) $tplName, 0, $matches[0][1]), '/Bundle/', '') .
Strings::replace(substr((string) $tplName, $matches[0][1]), '/:/', '/');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
final class AuthorizationCheckerToAccessDecisionManagerInVoterRector extends AbstractRector
{
private const string AUTHORIZATION_CHECKER_PROPERTY = 'authorizationChecker';

private const string ACCESS_DECISION_MANAGER_PROPERTY = 'accessDecisionManager';

public function getRuleDefinition(): RuleDefinition
Expand Down Expand Up @@ -97,19 +98,15 @@ public function refactor(Node $node): ?Node
$hasChanged = false;
$renamedProperties = [];

$authorizationCheckerType = new ObjectType(
SymfonyClass::AUTHORIZATION_CHECKER
);
$objectType = new ObjectType(SymfonyClass::AUTHORIZATION_CHECKER);

// 1) Regular properties
foreach ($node->getProperties() as $property) {
if (! $this->isObjectType($property, $authorizationCheckerType)) {
if (! $this->isObjectType($property, $objectType)) {
continue;
}

$property->type = new FullyQualified(
SymfonyClass::ACCESS_DECISION_MANAGER_INTERFACE
);
$property->type = new FullyQualified(SymfonyClass::ACCESS_DECISION_MANAGER_INTERFACE);

foreach ($property->props as $prop) {
if ($this->getName($prop) === self::AUTHORIZATION_CHECKER_PROPERTY) {
Expand All @@ -133,9 +130,7 @@ public function refactor(Node $node): ?Node
continue;
}

$param->type = new FullyQualified(
SymfonyClass::ACCESS_DECISION_MANAGER_INTERFACE
);
$param->type = new FullyQualified(SymfonyClass::ACCESS_DECISION_MANAGER_INTERFACE);

if (
$param->var instanceof Variable
Expand All @@ -155,7 +150,7 @@ public function refactor(Node $node): ?Node
if ($voteMethod instanceof ClassMethod) {
$this->traverseNodesWithCallable(
$voteMethod,
function (Node $node) use (&$hasChanged, $voteMethod, $renamedProperties) {
function (Node $node) use (&$hasChanged, $voteMethod, $renamedProperties): int|null|MethodCall {
if ($node instanceof Class_ || $node instanceof Function_) {
return NodeVisitor::DONT_TRAVERSE_CURRENT_AND_CHILDREN;
}
Expand All @@ -164,10 +159,7 @@ function (Node $node) use (&$hasChanged, $voteMethod, $renamedProperties) {
return null;
}

if (! $this->isObjectType(
$node->var,
new ObjectType(SymfonyClass::AUTHORIZATION_CHECKER)
)) {
if (! $this->isObjectType($node->var, new ObjectType(SymfonyClass::AUTHORIZATION_CHECKER))) {
return null;
}

Expand Down Expand Up @@ -199,12 +191,7 @@ function (Node $node) use (&$hasChanged, $voteMethod, $renamedProperties) {

$attributeExpr = $attributeArg->value;

$node->args = [
new Arg($tokenVariable),
new Arg(new Array_([
new ArrayItem($attributeExpr),
])),
];
$node->args = [new Arg($tokenVariable), new Arg(new Array_([new ArrayItem($attributeExpr)]))];

$hasChanged = true;
return $node;
Expand Down