@@ -136,13 +136,7 @@ public function refactor(Node $node): ?Class_
136
136
return null ;
137
137
}
138
138
139
- // 1. fetch configure method to get arguments and options metadata
140
- $ configureClassMethod = $ node ->getMethod (CommandMethodName::CONFIGURE );
141
- if (! $ configureClassMethod instanceof ClassMethod) {
142
- return null ;
143
- }
144
-
145
- // 2. rename execute to __invoke
139
+ // 1. rename execute to __invoke
146
140
$ executeClassMethod = $ node ->getMethod (CommandMethodName::EXECUTE );
147
141
if (! $ executeClassMethod instanceof ClassMethod) {
148
142
return null ;
@@ -151,19 +145,27 @@ public function refactor(Node $node): ?Class_
151
145
$ executeClassMethod ->name = new Identifier ('__invoke ' );
152
146
$ this ->visibilityManipulator ->makePublic ($ executeClassMethod );
153
147
154
- // 3. create arguments and options parameters
155
- // @todo
156
- $ commandArguments = $ this ->commandArgumentsAndOptionsResolver ->collectCommandArguments (
157
- $ configureClassMethod
158
- );
148
+ // 2. fetch configure method to get arguments and options metadata
149
+ $ configureClassMethod = $ node ->getMethod (CommandMethodName::CONFIGURE );
159
150
160
- $ commandOptions = $ this ->commandArgumentsAndOptionsResolver ->collectCommandOptions ($ configureClassMethod );
151
+ if ($ configureClassMethod instanceof ClassMethod) {
152
+ // 3. create arguments and options parameters
153
+ // @todo
154
+ $ commandArguments = $ this ->commandArgumentsAndOptionsResolver ->collectCommandArguments (
155
+ $ configureClassMethod
156
+ );
161
157
162
- // 4. remove configure() method
163
- $ this ->removeConfigureClassMethod ($ node );
158
+ $ commandOptions = $ this ->commandArgumentsAndOptionsResolver ->collectCommandOptions ($ configureClassMethod );
159
+
160
+ // 4. remove configure() method
161
+ $ this ->removeConfigureClassMethod ($ node );
162
+
163
+ // 5. decorate __invoke method with attributes
164
+ $ invokeParams = $ this ->commandInvokeParamsFactory ->createParams ($ commandArguments , $ commandOptions );
165
+ } else {
166
+ $ invokeParams = [];
167
+ }
164
168
165
- // 5. decorate __invoke method with attributes
166
- $ invokeParams = $ this ->commandInvokeParamsFactory ->createParams ($ commandArguments , $ commandOptions );
167
169
$ executeClassMethod ->params = array_merge ($ invokeParams , [$ executeClassMethod ->params [1 ]]);
168
170
169
171
// 6. remove parent class
@@ -181,8 +183,10 @@ public function refactor(Node $node): ?Class_
181
183
}
182
184
}
183
185
184
- // 7. replace input->getArgument() and input->getOption() calls with direct variable access
185
- $ this ->replaceInputArgumentOptionFetchWithVariables ($ executeClassMethod );
186
+ if ($ configureClassMethod instanceof ClassMethod) {
187
+ // 7. replace input->getArgument() and input->getOption() calls with direct variable access
188
+ $ this ->replaceInputArgumentOptionFetchWithVariables ($ executeClassMethod );
189
+ }
186
190
187
191
return $ node ;
188
192
}
0 commit comments