Complex classes like ResponseCalls often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use ResponseCalls, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
18 | class ResponseCalls extends Strategy |
||
19 | { |
||
20 | use ParamHelpers; |
||
21 | |||
22 | /** |
||
23 | * @param Route $route |
||
24 | * @param \ReflectionClass $controller |
||
25 | * @param \ReflectionMethod $method |
||
26 | * @param array $routeRules |
||
27 | * @param array $context |
||
28 | * |
||
29 | * @return array|null |
||
30 | */ |
||
31 | public function __invoke(Route $route, \ReflectionClass $controller, \ReflectionMethod $method, array $routeRules, array $context = []) |
||
61 | |||
62 | /** |
||
63 | * @param array $rulesToApply |
||
64 | * |
||
65 | * @return void |
||
66 | */ |
||
67 | private function configureEnvironment(array $rulesToApply) |
||
73 | |||
74 | /** |
||
75 | * @param Route $route |
||
76 | * @param array $rulesToApply |
||
77 | * @param array $bodyParams |
||
78 | * @param array $queryParams |
||
79 | * |
||
80 | * @return Request |
||
81 | */ |
||
82 | protected function prepareRequest(Route $route, array $rulesToApply, array $bodyParams, array $queryParams) |
||
96 | |||
97 | /** |
||
98 | * @param array $env |
||
99 | * |
||
100 | * @return void |
||
101 | * |
||
102 | * @deprecated in favour of Laravel config variables |
||
103 | */ |
||
104 | private function setEnvironmentVariables(array $env) |
||
113 | |||
114 | /** |
||
115 | * @param array $config |
||
116 | * |
||
117 | * @return void |
||
118 | */ |
||
119 | private function setLaravelConfigs(array $config) |
||
129 | |||
130 | /** |
||
131 | * @return void |
||
132 | */ |
||
133 | private function startDbTransaction() |
||
140 | |||
141 | /** |
||
142 | * @return void |
||
143 | */ |
||
144 | private function endDbTransaction() |
||
151 | |||
152 | /** |
||
153 | * @return void |
||
154 | */ |
||
155 | private function finish() |
||
159 | |||
160 | /** |
||
161 | * @param Request $request |
||
162 | * |
||
163 | * @return \Illuminate\Http\JsonResponse|mixed |
||
164 | */ |
||
165 | public function callDingoRoute(Request $request) |
||
194 | |||
195 | /** |
||
196 | * @param Route $route |
||
197 | * |
||
198 | * @return array |
||
199 | */ |
||
200 | public function getMethods(Route $route) |
||
204 | |||
205 | /** |
||
206 | * @param Request $request |
||
207 | * @param Route $route |
||
208 | * @param array|null $headers |
||
209 | * |
||
210 | * @return Request |
||
211 | */ |
||
212 | private function addHeaders(Request $request, Route $route, $headers) |
||
233 | |||
234 | /** |
||
235 | * @param Request $request |
||
236 | * @param array $query |
||
237 | * |
||
238 | * @return Request |
||
239 | */ |
||
240 | private function addQueryParameters(Request $request, array $query) |
||
247 | |||
248 | /** |
||
249 | * @param Request $request |
||
250 | * @param array $body |
||
251 | * |
||
252 | * @return Request |
||
253 | */ |
||
254 | private function addBodyParameters(Request $request, array $body) |
||
260 | |||
261 | /** |
||
262 | * @param Request $request |
||
263 | * |
||
264 | * @throws \Exception |
||
265 | * |
||
266 | * @return \Illuminate\Http\JsonResponse|mixed|\Symfony\Component\HttpFoundation\Response |
||
267 | */ |
||
268 | protected function makeApiCall(Request $request) |
||
278 | |||
279 | /** |
||
280 | * @param Request $request |
||
281 | * |
||
282 | * @throws \Exception |
||
283 | * |
||
284 | * @return \Symfony\Component\HttpFoundation\Response |
||
285 | */ |
||
286 | protected function callLaravelRoute(Request $request): \Symfony\Component\HttpFoundation\Response |
||
294 | |||
295 | /** |
||
296 | * @param Route $route |
||
297 | * @param array $rulesToApply |
||
298 | * |
||
299 | * @return bool |
||
300 | */ |
||
301 | private function shouldMakeApiCall(Route $route, array $rulesToApply, array $context): bool |
||
328 | |||
329 | /** |
||
330 | * Transform headers array to array of $_SERVER vars with HTTP_* format. |
||
331 | * |
||
332 | * @param array $headers |
||
333 | * |
||
334 | * @return array |
||
335 | */ |
||
336 | protected function transformHeadersToServerVars(array $headers) |
||
350 | } |
||
351 |
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.