Complex classes like StringType 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 StringType, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
13 | class StringType extends AbstractType |
||
14 | { |
||
15 | |||
16 | private static $formats = array( |
||
17 | 'string' => '', |
||
18 | 'byte' => 'byte', |
||
19 | 'binary' => 'binary', |
||
20 | 'password' => 'password', |
||
21 | 'enum' => '', |
||
22 | ); |
||
23 | |||
24 | /** |
||
25 | * Name of the type |
||
26 | * @var string |
||
27 | */ |
||
28 | protected $format = ''; |
||
29 | protected $pattern = null; |
||
30 | protected $default = null; |
||
31 | protected $maxLength = null; |
||
32 | protected $minLength = null; |
||
33 | protected $enum = array(); |
||
34 | |||
35 | protected function parseDefinition($definition) |
||
49 | |||
50 | /** |
||
51 | * @param string $definition |
||
52 | * @param string[] $match |
||
53 | */ |
||
54 | private function parseFormat($definition, $match) |
||
62 | |||
63 | /** |
||
64 | * @param string $definition |
||
65 | * @param string[] $match |
||
66 | */ |
||
67 | private function parseContent($definition, $match) |
||
75 | |||
76 | /** |
||
77 | * @param string $definition |
||
78 | * @param string[] $match |
||
79 | */ |
||
80 | private function parseRange($definition, $match) |
||
102 | |||
103 | /** |
||
104 | * @param string $definition |
||
105 | * @param string[] $match |
||
106 | */ |
||
107 | private function parseDefault($definition, $match) |
||
111 | |||
112 | /** |
||
113 | * @param string $command The comment command |
||
114 | * @param string $data Any data added after the command |
||
115 | * @return \SwaggerGen\Swagger\Type\AbstractType|boolean |
||
116 | */ |
||
117 | public function handleCommand($command, $data = null) |
||
139 | |||
140 | public function toArray() |
||
152 | |||
153 | /** |
||
154 | * Validate a default string value, depending on subtype |
||
155 | * |
||
156 | * @param string $value the value to validate |
||
157 | * @return string the value after validation (may be trimmed and such) |
||
158 | * @throws \SwaggerGen\Exception |
||
159 | */ |
||
160 | protected function validateDefault($value) |
||
183 | |||
184 | public function __toString() |
||
188 | |||
189 | } |
||
190 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.