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) |
||
| 71 | |||
| 72 | /** |
||
| 73 | * Prepares / Disables route middlewares. |
||
| 74 | * |
||
| 75 | * @param bool $disable |
||
| 76 | * |
||
| 77 | * @return void |
||
| 78 | */ |
||
| 79 | abstract public function prepareMiddleware($enable = false); |
||
| 80 | |||
| 81 | /** |
||
| 82 | * Get the response from the docblock if available. |
||
| 83 | * |
||
| 84 | * @param array $tags |
||
| 85 | * |
||
| 86 | * @return mixed |
||
| 87 | */ |
||
| 88 | protected function getDocblockResponse($tags) |
||
| 100 | |||
| 101 | /** |
||
| 102 | * @param array $tags |
||
| 103 | * |
||
| 104 | * @return array |
||
| 105 | */ |
||
| 106 | protected function getParametersFromDocBlock($tags) |
||
| 123 | |||
| 124 | /** |
||
| 125 | * @param $route |
||
| 126 | * @param $bindings |
||
| 127 | * @param $headers |
||
| 128 | * |
||
| 129 | * @return \Illuminate\Http\Response |
||
| 130 | */ |
||
| 131 | protected function getRouteResponse($route, $bindings, $headers = []) |
||
| 151 | |||
| 152 | /** |
||
| 153 | * @param $route |
||
| 154 | * @param array $bindings |
||
| 155 | * |
||
| 156 | * @return mixed |
||
| 157 | */ |
||
| 158 | protected function addRouteModelBindings($route, $bindings) |
||
| 168 | |||
| 169 | /** |
||
| 170 | * @param \Illuminate\Routing\Route $route |
||
| 171 | * |
||
| 172 | * @return array |
||
| 173 | */ |
||
| 174 | protected function parseDocBlock($route) |
||
| 189 | |||
| 190 | /** |
||
| 191 | * @param string $route |
||
| 192 | * |
||
| 193 | * @return string |
||
| 194 | */ |
||
| 195 | protected function getRouteGroup($route) |
||
| 211 | |||
| 212 | /** |
||
| 213 | * Call the given URI and return the Response. |
||
| 214 | * |
||
| 215 | * @param string $method |
||
| 216 | * @param string $uri |
||
| 217 | * @param array $parameters |
||
| 218 | * @param array $cookies |
||
| 219 | * @param array $files |
||
| 220 | * @param array $server |
||
| 221 | * @param string $content |
||
| 222 | * |
||
| 223 | * @return \Illuminate\Http\Response |
||
| 224 | */ |
||
| 225 | abstract public function callRoute($method, $uri, $parameters = [], $cookies = [], $files = [], $server = [], $content = null); |
||
| 226 | |||
| 227 | /** |
||
| 228 | * Transform headers array to array of $_SERVER vars with HTTP_* format. |
||
| 229 | * |
||
| 230 | * @param array $headers |
||
| 231 | * |
||
| 232 | * @return array |
||
| 233 | */ |
||
| 234 | protected function transformHeadersToServerVars(array $headers) |
||
| 251 | |||
| 252 | /** |
||
| 253 | * @param $response |
||
| 254 | * |
||
| 255 | * @return mixed |
||
| 256 | */ |
||
| 257 | private function getResponseContent($response) |
||
| 270 | |||
| 271 | /** |
||
| 272 | * Get a response from the transformer tags. |
||
| 273 | * |
||
| 274 | * @param array $tags |
||
| 275 | * |
||
| 276 | * @return mixed |
||
| 277 | */ |
||
| 278 | protected function getTransformerResponse($tags) |
||
| 362 | |||
| 363 | private function getResponse(array $annotationTags) |
||
| 379 | |||
| 380 | private function normalizeParameterType($type) |
||
| 389 | } |
||
| 390 |