Complex classes like AbstractGenerator 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 AbstractGenerator, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 14 | abstract class AbstractGenerator |
||
| 15 | { |
||
| 16 | /** |
||
| 17 | * @param Route $route |
||
| 18 | * |
||
| 19 | * @return mixed |
||
| 20 | */ |
||
| 21 | public function getDomain(Route $route) |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @param Route $route |
||
| 28 | * |
||
| 29 | * @return mixed |
||
| 30 | */ |
||
| 31 | public function getUri(Route $route) |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @param Route $route |
||
| 38 | * |
||
| 39 | * @return mixed |
||
| 40 | */ |
||
| 41 | public function getMethods(Route $route) |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @param \Illuminate\Routing\Route $route |
||
| 48 | * @param array $apply Rules to apply when generating documentation for this route |
||
| 49 | * |
||
| 50 | * @return array |
||
| 51 | */ |
||
| 52 | public function processRoute($route, $apply = []) |
||
| 89 | |||
| 90 | /** |
||
| 91 | * Prepares / Disables route middlewares. |
||
| 92 | * |
||
| 93 | * @param bool $disable |
||
| 94 | * |
||
| 95 | * @return void |
||
| 96 | */ |
||
| 97 | abstract public function prepareMiddleware($enable = false); |
||
| 98 | |||
| 99 | /** |
||
| 100 | * Get the response from the docblock if available. |
||
| 101 | * |
||
| 102 | * @param array $tags |
||
| 103 | * |
||
| 104 | * @return mixed |
||
| 105 | */ |
||
| 106 | protected function getDocblockResponse($tags) |
||
| 122 | |||
| 123 | /** |
||
| 124 | * @param array $routeAction |
||
| 125 | * @return array |
||
| 126 | */ |
||
| 127 | protected function getParametersFromDocBlock($routeAction) |
||
| 131 | |||
| 132 | /** |
||
| 133 | * @param $route |
||
| 134 | * @param $bindings |
||
| 135 | * @param $headers |
||
| 136 | * |
||
| 137 | * @return \Illuminate\Http\Response |
||
| 138 | */ |
||
| 139 | protected function getRouteResponse($route, $bindings, $headers = []) |
||
| 159 | |||
| 160 | /** |
||
| 161 | * @param $route |
||
| 162 | * @param array $bindings |
||
| 163 | * |
||
| 164 | * @return mixed |
||
| 165 | */ |
||
| 166 | protected function addRouteModelBindings($route, $bindings) |
||
| 176 | |||
| 177 | /** |
||
| 178 | * @param \Illuminate\Routing\Route $route |
||
| 179 | * |
||
| 180 | * @return array |
||
| 181 | */ |
||
| 182 | protected function getRouteDescription($route) |
||
| 197 | |||
| 198 | /** |
||
| 199 | * @param string $route |
||
| 200 | * |
||
| 201 | * @return string |
||
| 202 | */ |
||
| 203 | protected function getRouteGroup($route) |
||
| 219 | |||
| 220 | /** |
||
| 221 | * Call the given URI and return the Response. |
||
| 222 | * |
||
| 223 | * @param string $method |
||
| 224 | * @param string $uri |
||
| 225 | * @param array $parameters |
||
| 226 | * @param array $cookies |
||
| 227 | * @param array $files |
||
| 228 | * @param array $server |
||
| 229 | * @param string $content |
||
| 230 | * |
||
| 231 | * @return \Illuminate\Http\Response |
||
| 232 | */ |
||
| 233 | abstract public function callRoute($method, $uri, $parameters = [], $cookies = [], $files = [], $server = [], $content = null); |
||
| 234 | |||
| 235 | /** |
||
| 236 | * Transform headers array to array of $_SERVER vars with HTTP_* format. |
||
| 237 | * |
||
| 238 | * @param array $headers |
||
| 239 | * |
||
| 240 | * @return array |
||
| 241 | */ |
||
| 242 | protected function transformHeadersToServerVars(array $headers) |
||
| 259 | |||
| 260 | /** |
||
| 261 | * @param $response |
||
| 262 | * |
||
| 263 | * @return mixed |
||
| 264 | */ |
||
| 265 | private function getResponseContent($response) |
||
| 278 | |||
| 279 | /** |
||
| 280 | * Get a response from the transformer tags. |
||
| 281 | * |
||
| 282 | * @param array $tags |
||
| 283 | * |
||
| 284 | * @return mixed |
||
| 285 | */ |
||
| 286 | protected function getTransformerResponse($tags) |
||
| 371 | } |
||
| 372 |