Complex classes like Compiler 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 Compiler, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
12 | class Compiler extends MixinVisitor |
||
13 | { |
||
14 | /** |
||
15 | * Constants and configuration in Compiler/CompilerConfig.php. |
||
16 | */ |
||
17 | |||
18 | /** |
||
19 | * @var |
||
20 | */ |
||
21 | protected $xml; |
||
22 | |||
23 | /** |
||
24 | * @var |
||
25 | */ |
||
26 | protected $parentIndents; |
||
27 | |||
28 | /** |
||
29 | * @var array |
||
30 | */ |
||
31 | protected $buffer = array(); |
||
32 | /** |
||
33 | * @var array |
||
34 | */ |
||
35 | protected $options = array(); |
||
36 | /** |
||
37 | * @var array |
||
38 | */ |
||
39 | protected $filters = array(); |
||
40 | |||
41 | /** |
||
42 | * @var bool |
||
43 | */ |
||
44 | protected $phpSingleLine = false; |
||
45 | /** |
||
46 | * @var bool |
||
47 | */ |
||
48 | protected $allowMixinOverride = false; |
||
49 | /** |
||
50 | * @var bool |
||
51 | */ |
||
52 | protected $keepNullAttributes = false; |
||
53 | /** |
||
54 | * @var bool |
||
55 | */ |
||
56 | protected $filterAutoLoad = true; |
||
57 | /** |
||
58 | * @var bool |
||
59 | */ |
||
60 | protected $terse = true; |
||
61 | /** |
||
62 | * @var bool |
||
63 | */ |
||
64 | protected $restrictedScope = false; |
||
65 | /** |
||
66 | * @var array |
||
67 | */ |
||
68 | protected $customKeywords = array(); |
||
69 | /** |
||
70 | * @var Jade |
||
71 | */ |
||
72 | protected $jade = null; |
||
73 | |||
74 | /** |
||
75 | * @var string |
||
76 | */ |
||
77 | protected $quote; |
||
78 | |||
79 | /** |
||
80 | * @var string |
||
81 | */ |
||
82 | protected $filename; |
||
83 | |||
84 | /** |
||
85 | * @param array/Jade $options |
||
|
|||
86 | * @param array $filters |
||
87 | */ |
||
88 | public function __construct($options = array(), array $filters = array(), $filename = null) |
||
94 | |||
95 | /** |
||
96 | * Get a jade engine reference or an options array and return needed options. |
||
97 | * |
||
98 | * @param array/Jade $options |
||
99 | * |
||
100 | * @return array |
||
101 | */ |
||
102 | protected function setOptions($options) |
||
140 | |||
141 | /** |
||
142 | * Get an option from the jade engine if set or from the options array else. |
||
143 | * |
||
144 | * @param string $option |
||
145 | * |
||
146 | * @throws \InvalidArgumentException |
||
147 | * |
||
148 | * @return mixed |
||
149 | */ |
||
150 | public function getOption($option) |
||
162 | |||
163 | /** |
||
164 | * Get a compiler with the same settings. |
||
165 | * |
||
166 | * @return Compiler |
||
167 | */ |
||
168 | public function subCompiler() |
||
172 | |||
173 | /** |
||
174 | * php closing tag depanding on the pretty print setting. |
||
175 | * |
||
176 | * @return string |
||
177 | */ |
||
178 | protected function closingTag() |
||
182 | |||
183 | /** |
||
184 | * @param $node |
||
185 | * |
||
186 | * @return string |
||
187 | */ |
||
188 | public function compile($node) |
||
201 | |||
202 | /** |
||
203 | * @param $method |
||
204 | * @param $arguments |
||
205 | * |
||
206 | * @throws \BadMethodCallException If the 'apply' rely on non existing method |
||
207 | * |
||
208 | * @return mixed |
||
209 | */ |
||
210 | protected function apply($method, $arguments) |
||
218 | |||
219 | /** |
||
220 | * @param $line |
||
221 | * @param null $indent |
||
222 | */ |
||
223 | protected function buffer($line, $indent = null) |
||
231 | |||
232 | /** |
||
233 | * @param string $str |
||
234 | * |
||
235 | * @return bool|int |
||
236 | */ |
||
237 | protected function isConstant($str) |
||
241 | |||
242 | /** |
||
243 | * @param $input |
||
244 | * @param string $name |
||
245 | * |
||
246 | * @throws \ErrorException |
||
247 | * |
||
248 | * @return array |
||
249 | */ |
||
250 | public function handleCode($input, $name = '') |
||
256 | |||
257 | /** |
||
258 | * @param $input |
||
259 | * |
||
260 | * @throws \ErrorException |
||
261 | * |
||
262 | * @return array |
||
263 | */ |
||
264 | public function handleString($input) |
||
311 | |||
312 | /** |
||
313 | * @param string $text |
||
314 | * |
||
315 | * @return mixed |
||
316 | */ |
||
317 | public function interpolate($text) |
||
321 | |||
322 | /** |
||
323 | * @param array $match |
||
324 | * |
||
325 | * @return string |
||
326 | */ |
||
327 | protected function interpolateFromCapture($match) |
||
335 | |||
336 | /** |
||
337 | * @throws \InvalidArgumentException |
||
338 | * |
||
339 | * @return array |
||
340 | */ |
||
341 | protected function createStatements() |
||
381 | |||
382 | protected function handleArgumentValue($arg) |
||
399 | |||
400 | /** |
||
401 | * @param $code |
||
402 | * @param null $statements |
||
403 | * |
||
404 | * @return string |
||
405 | */ |
||
406 | protected function createPhpBlock($code, $statements = null) |
||
435 | |||
436 | /** |
||
437 | * @param $code |
||
438 | * |
||
439 | * @return string |
||
440 | */ |
||
441 | protected function createCode($code) |
||
453 | } |
||
454 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.