Skip to content

Commit 54ebd77

Browse files
authored
cs (#918)
1 parent 582fc7c commit 54ebd77

4 files changed

Lines changed: 15 additions & 26 deletions

File tree

rules-tests/Symfony73/Rector/Class_/AuthorizationCheckerToAccessDecisionManagerInVoterRector/config/configured_rule.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,4 @@
66
use Rector\Symfony\Symfony73\Rector\Class_\AuthorizationCheckerToAccessDecisionManagerInVoterRector;
77

88
return RectorConfig::configure()
9-
->withRules([
10-
AuthorizationCheckerToAccessDecisionManagerInVoterRector::class,
11-
]);
9+
->withRules([AuthorizationCheckerToAccessDecisionManagerInVoterRector::class]);

rules/Configs/NodeVisitor/CollectServiceArgumentsNodeVisitor.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,12 @@ private function matchStringEnvOrParameter(
183183
): void {
184184
$match = Strings::match($argumentValue, '#%env\((?<env>[A-Z_]+)\)#');
185185
if (isset($match['env'])) {
186-
$this->servicesArgumentsByClass[$serviceClassName][self::ENVS][$argumentLocation] = (string) $match['env'];
186+
$this->servicesArgumentsByClass[$serviceClassName][self::ENVS][$argumentLocation] = $match['env'];
187187
}
188188

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

rules/Symfony43/Rector/MethodCall/ConvertRenderTemplateShortNotationToBundleSyntaxRector.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ public function refactor(Node $node): ?Node
111111
return null;
112112
}
113113

114+
if (! isset($matches[0])) {
115+
return null;
116+
}
117+
114118
$newValue = '@' .
115119
Strings::replace(substr((string) $tplName, 0, $matches[0][1]), '/Bundle/', '') .
116120
Strings::replace(substr((string) $tplName, $matches[0][1]), '/:/', '/');

rules/Symfony73/Rector/Class_/AuthorizationCheckerToAccessDecisionManagerInVoterRector.php

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
final class AuthorizationCheckerToAccessDecisionManagerInVoterRector extends AbstractRector
3030
{
3131
private const string AUTHORIZATION_CHECKER_PROPERTY = 'authorizationChecker';
32+
3233
private const string ACCESS_DECISION_MANAGER_PROPERTY = 'accessDecisionManager';
3334

3435
public function getRuleDefinition(): RuleDefinition
@@ -97,19 +98,15 @@ public function refactor(Node $node): ?Node
9798
$hasChanged = false;
9899
$renamedProperties = [];
99100

100-
$authorizationCheckerType = new ObjectType(
101-
SymfonyClass::AUTHORIZATION_CHECKER
102-
);
101+
$objectType = new ObjectType(SymfonyClass::AUTHORIZATION_CHECKER);
103102

104103
// 1) Regular properties
105104
foreach ($node->getProperties() as $property) {
106-
if (! $this->isObjectType($property, $authorizationCheckerType)) {
105+
if (! $this->isObjectType($property, $objectType)) {
107106
continue;
108107
}
109108

110-
$property->type = new FullyQualified(
111-
SymfonyClass::ACCESS_DECISION_MANAGER_INTERFACE
112-
);
109+
$property->type = new FullyQualified(SymfonyClass::ACCESS_DECISION_MANAGER_INTERFACE);
113110

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

136-
$param->type = new FullyQualified(
137-
SymfonyClass::ACCESS_DECISION_MANAGER_INTERFACE
138-
);
133+
$param->type = new FullyQualified(SymfonyClass::ACCESS_DECISION_MANAGER_INTERFACE);
139134

140135
if (
141136
$param->var instanceof Variable
@@ -155,7 +150,7 @@ public function refactor(Node $node): ?Node
155150
if ($voteMethod instanceof ClassMethod) {
156151
$this->traverseNodesWithCallable(
157152
$voteMethod,
158-
function (Node $node) use (&$hasChanged, $voteMethod, $renamedProperties) {
153+
function (Node $node) use (&$hasChanged, $voteMethod, $renamedProperties): int|null|MethodCall {
159154
if ($node instanceof Class_ || $node instanceof Function_) {
160155
return NodeVisitor::DONT_TRAVERSE_CURRENT_AND_CHILDREN;
161156
}
@@ -164,10 +159,7 @@ function (Node $node) use (&$hasChanged, $voteMethod, $renamedProperties) {
164159
return null;
165160
}
166161

167-
if (! $this->isObjectType(
168-
$node->var,
169-
new ObjectType(SymfonyClass::AUTHORIZATION_CHECKER)
170-
)) {
162+
if (! $this->isObjectType($node->var, new ObjectType(SymfonyClass::AUTHORIZATION_CHECKER))) {
171163
return null;
172164
}
173165

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

200192
$attributeExpr = $attributeArg->value;
201193

202-
$node->args = [
203-
new Arg($tokenVariable),
204-
new Arg(new Array_([
205-
new ArrayItem($attributeExpr),
206-
])),
207-
];
194+
$node->args = [new Arg($tokenVariable), new Arg(new Array_([new ArrayItem($attributeExpr)]))];
208195

209196
$hasChanged = true;
210197
return $node;

0 commit comments

Comments
 (0)