Complex classes like OptionsMethods 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 OptionsMethods, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 22 | final class OptionsMethods |
||
| 23 | { |
||
| 24 | /** |
||
| 25 | * Constants for annotation name and "in" name |
||
| 26 | * |
||
| 27 | * @var array |
||
| 28 | */ |
||
| 29 | private $webContextName = [ |
||
| 30 | CookieParam::class => 'cookie', |
||
| 31 | EnvParam::class => 'env', |
||
| 32 | FormParam::class => 'formData', |
||
| 33 | QueryParam::class => 'query', |
||
| 34 | ServerParam::class => 'server' |
||
| 35 | ]; |
||
| 36 | private $reader; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @var string |
||
| 40 | */ |
||
| 41 | private $schemaDir; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @Named("schemaDir=json_schema_dir") |
||
| 45 | */ |
||
| 46 | 86 | public function __construct(Reader $reader, $schemaDir = '') |
|
| 51 | |||
| 52 | /** |
||
| 53 | * @param ResourceObject $ro |
||
| 54 | * @param string $requestMethod |
||
| 55 | * |
||
| 56 | * @return array |
||
| 57 | */ |
||
| 58 | 6 | public function __invoke(ResourceObject $ro, $requestMethod) |
|
| 85 | |||
| 86 | 6 | private function getInMap(\ReflectionMethod $method) |
|
| 98 | |||
| 99 | /** |
||
| 100 | * @param string $docComment |
||
| 101 | * |
||
| 102 | * @return array [$docs, $params] |
||
| 103 | */ |
||
| 104 | 6 | private function docBlock($docComment) |
|
| 122 | |||
| 123 | /** |
||
| 124 | * @param \ReflectionParameter $parameter |
||
| 125 | * @param array $paramDoc |
||
| 126 | * @param string $name |
||
| 127 | * |
||
| 128 | * @return string|null |
||
| 129 | */ |
||
| 130 | 6 | private function getParameterType(\ReflectionParameter $parameter, array $paramDoc, $name) |
|
| 140 | |||
| 141 | /** |
||
| 142 | * @param \ReflectionParameter[] $parameters |
||
| 143 | * @param array $paramDoc |
||
| 144 | * |
||
| 145 | * @return array [$paramDoc, $required] |
||
| 146 | */ |
||
| 147 | 6 | private function getParameterMetas(array $parameters, array $paramDoc, array $ins) |
|
| 166 | |||
| 167 | /** |
||
| 168 | * @return array |
||
| 169 | */ |
||
| 170 | 6 | private function paramDefault(array $paramDoc, \ReflectionParameter $parameter) |
|
| 179 | |||
| 180 | /** |
||
| 181 | * @return array |
||
| 182 | */ |
||
| 183 | 6 | private function paramType(array $paramDoc, \ReflectionParameter $parameter) |
|
| 192 | |||
| 193 | /** |
||
| 194 | * @param \ReflectionParameter $parameter |
||
| 195 | * |
||
| 196 | * @return string |
||
| 197 | */ |
||
| 198 | 1 | private function getType(\ReflectionParameter $parameter) |
|
| 207 | |||
| 208 | /** |
||
| 209 | * @return array |
||
| 210 | */ |
||
| 211 | 6 | private function docBlogTags(array $tags, array $params) |
|
| 229 | |||
| 230 | /** |
||
| 231 | * Ignore @ Assisted @ ResourceParam parameter |
||
| 232 | * |
||
| 233 | * @return array |
||
| 234 | */ |
||
| 235 | 6 | private function ignoreAnnotatedPrameter(\ReflectionMethod $method, array $paramMetas) |
|
| 250 | |||
| 251 | /** |
||
| 252 | * Ignore @ Assisted parameter |
||
| 253 | * |
||
| 254 | * @return array |
||
| 255 | */ |
||
| 256 | 1 | private function ignorreAssisted(array $paramMetas, Assisted $annotation) |
|
| 265 | |||
| 266 | 6 | private function getJsonSchema(\ReflectionMethod $method) |
|
| 279 | } |
||
| 280 |