Complex classes like Validator 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 Validator, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
15 | class Validator |
||
16 | { |
||
17 | |||
18 | /** |
||
19 | * @param array $value |
||
20 | * @return bool |
||
21 | */ |
||
22 | public function noArguments(array $value) |
||
26 | |||
27 | /** |
||
28 | * @param array $value |
||
29 | * @return bool |
||
30 | */ |
||
31 | public function bestFit(array $value) |
||
35 | |||
36 | /** |
||
37 | * @param array $value |
||
38 | * @return bool |
||
39 | */ |
||
40 | public function flip(array $value) |
||
44 | |||
45 | /** |
||
46 | * @param array $value |
||
47 | * @return bool |
||
48 | */ |
||
49 | public function overlay(array $value) |
||
66 | |||
67 | /** |
||
68 | * @param array $value |
||
69 | * @return bool |
||
70 | */ |
||
71 | public function rotate(array $value) |
||
83 | |||
84 | /** |
||
85 | * @param array $value |
||
86 | * @return bool |
||
87 | */ |
||
88 | public function border(array $value) |
||
92 | |||
93 | /** |
||
94 | * @param array $value |
||
95 | * @return bool |
||
96 | */ |
||
97 | public function blur(array $value) |
||
101 | |||
102 | /** |
||
103 | * @param array $value |
||
104 | * @return bool |
||
105 | */ |
||
106 | public function brighten(array $value) |
||
110 | |||
111 | /** |
||
112 | * @param array $value |
||
113 | * @return bool |
||
114 | */ |
||
115 | public function contrast(array $value) |
||
121 | |||
122 | /** |
||
123 | * @param array $value |
||
124 | * @return bool |
||
125 | */ |
||
126 | public function darken(array $value) |
||
130 | |||
131 | /** |
||
132 | * @param array $value |
||
133 | * @return bool |
||
134 | */ |
||
135 | public function duotone(array $value) |
||
139 | |||
140 | /** |
||
141 | * @param array $value |
||
142 | * @return bool |
||
143 | */ |
||
144 | public function opacity(array $value) |
||
148 | |||
149 | /** |
||
150 | * @param array $value |
||
151 | * @return bool |
||
152 | */ |
||
153 | public function pixelate(array $value) |
||
157 | |||
158 | /** |
||
159 | * @param array $value |
||
160 | * @return bool |
||
161 | */ |
||
162 | public function color(array $value) |
||
166 | |||
167 | /** |
||
168 | * Whether the value is a HEX color code |
||
169 | * @param string $value |
||
170 | * @return bool |
||
171 | */ |
||
172 | protected function isHex($value) |
||
176 | |||
177 | } |
||
178 |