2929final 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