Complex classes like ArrayType 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 ArrayType, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
13 | class ArrayType extends AbstractType |
||
14 | { |
||
15 | |||
16 | const REGEX_ARRAY_CONTENT = '(?:(\[)(.*)\])?'; |
||
17 | |||
18 | private static $classTypes = array( |
||
19 | 'integer' => 'Integer', |
||
20 | 'int' => 'Integer', |
||
21 | 'int32' => 'Integer', |
||
22 | 'int64' => 'Integer', |
||
23 | 'long' => 'Integer', |
||
24 | 'float' => 'Number', |
||
25 | 'double' => 'Number', |
||
26 | 'string' => 'String', |
||
27 | 'uuid' => 'StringUuid', |
||
28 | 'byte' => 'String', |
||
29 | 'binary' => 'String', |
||
30 | 'password' => 'String', |
||
31 | 'enum' => 'String', |
||
32 | 'boolean' => 'Boolean', |
||
33 | 'bool' => 'Boolean', |
||
34 | 'array' => 'Array', |
||
35 | 'csv' => 'Array', |
||
36 | 'ssv' => 'Array', |
||
37 | 'tsv' => 'Array', |
||
38 | 'pipes' => 'Array', |
||
39 | 'date' => 'Date', |
||
40 | 'datetime' => 'Date', |
||
41 | 'date-time' => 'Date', |
||
42 | 'object' => 'Object', |
||
43 | ); |
||
44 | private static $collectionFormats = array( |
||
45 | 'array' => 'csv', |
||
46 | 'csv' => 'csv', |
||
47 | 'ssv' => 'ssv', |
||
48 | 'tsv' => 'tsv', |
||
49 | 'pipes' => 'pipes', |
||
50 | 'multi' => 'multi', |
||
51 | ); |
||
52 | |||
53 | /** |
||
54 | * @var AbstractType |
||
55 | */ |
||
56 | private $Items = null; |
||
57 | private $minItems = null; |
||
58 | private $maxItems = null; |
||
59 | private $collectionFormat = null; |
||
60 | |||
61 | protected function parseDefinition($definition) |
||
77 | |||
78 | private function parseFormat($definition, $match) |
||
94 | |||
95 | private function parseItems($definition, $match) |
||
101 | |||
102 | private function parseRange($definition, $match) |
||
121 | |||
122 | /** |
||
123 | * @param string $command The comment command |
||
124 | * @param string $data Any data added after the command |
||
125 | * @return \SwaggerGen\Swagger\Type\AbstractType|boolean |
||
126 | */ |
||
127 | public function handleCommand($command, $data = null) |
||
164 | |||
165 | public function toArray() |
||
175 | |||
176 | private function validateItems($items) |
||
201 | |||
202 | public function __toString() |
||
206 | |||
207 | } |
||
208 |
This check looks for the bodies of
if
statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.These
if
bodies can be removed. If you have an empty if but statements in theelse
branch, consider inverting the condition.could be turned into
This is much more concise to read.