Complex classes like Generator 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 Generator, and based on these observations, apply Extract Interface, too.
1 | <?php declare(strict_types=1); |
||
10 | class Generator |
||
11 | { |
||
12 | /** Single quote for string value **/ |
||
13 | const QUOTE_SINGLE = "'"; |
||
14 | |||
15 | /** Double quote for string value **/ |
||
16 | const QUOTE_DOUBLE = '"'; |
||
17 | |||
18 | /** No quote for string heredoc value **/ |
||
19 | const QUOTE_NO = ''; |
||
20 | |||
21 | |||
22 | /** @var string Generated code */ |
||
23 | public $code = ''; |
||
24 | |||
25 | /** @var integer Level of code line tabbing for new lines */ |
||
26 | public $tabs = 0; |
||
27 | |||
28 | /** @var string Current class name */ |
||
29 | public $class; |
||
30 | |||
31 | /** @var int Current conditions nesting level */ |
||
32 | public $ifConditionLevel = 0; |
||
33 | |||
34 | /** |
||
35 | * Constructor |
||
36 | * |
||
37 | * @param string $namespace Code namespace |
||
38 | * |
||
39 | * @deprecated Use new generators logic |
||
40 | */ |
||
41 | public function __construct($namespace = null) |
||
48 | |||
49 | /** |
||
50 | * Add namespace declaration. |
||
51 | * |
||
52 | * @param string $name Namespace name |
||
53 | * |
||
54 | * @deprecated Use new generators logic |
||
55 | * @return $this Chaining |
||
56 | */ |
||
57 | public function defNamespace($name) |
||
65 | |||
66 | /** |
||
67 | * Add new line to code. |
||
68 | * |
||
69 | * @param string $text Code to add to new line |
||
70 | * @param integer $tabs Tabs count |
||
71 | * |
||
72 | *@return self |
||
73 | * @deprecated Use new generators logic |
||
74 | */ |
||
75 | public function newLine($text = '', $tabs = null) |
||
84 | |||
85 | /** |
||
86 | * Add current tabbing level to current line. |
||
87 | * |
||
88 | * @param string $endText Text to add after tabs |
||
89 | * @param integer $tabs Amount of tabs to add |
||
90 | * @param string $startText Text to add before tabs |
||
91 | * |
||
92 | * @return Generator Chaining |
||
93 | * @deprecated Use new generators logic |
||
94 | */ |
||
95 | public function tabs($endText = '', $tabs = null, $startText = '') |
||
105 | |||
106 | /** |
||
107 | * Add simple text to current code position |
||
108 | * |
||
109 | * @param string $text Text to add |
||
110 | * |
||
111 | * @return self |
||
112 | * @deprecated Use new generators logic |
||
113 | */ |
||
114 | public function text($text = '') |
||
120 | |||
121 | /** |
||
122 | * Increase current code indentation. |
||
123 | * |
||
124 | * @param int $amount Indentation amount |
||
125 | * |
||
126 | * @deprecated Use new generators logic |
||
127 | * |
||
128 | * @return $this Chaining |
||
129 | */ |
||
130 | public function increaseIndentation($amount = 1) |
||
136 | |||
137 | /** |
||
138 | * Reduce current code indentation. |
||
139 | * |
||
140 | * @param int $amount Indentation amount |
||
141 | * |
||
142 | * @deprecated Use new generators logic |
||
143 | * |
||
144 | * @return $this Chaining |
||
145 | */ |
||
146 | public function decreaseIndentation($amount = 1) |
||
152 | |||
153 | /** |
||
154 | * Add single line comment to code |
||
155 | * |
||
156 | * @param string $text Comment text |
||
157 | * |
||
158 | * @return self Chaining |
||
159 | * @deprecated Use new generators logic |
||
160 | */ |
||
161 | public function comment($text = '') |
||
165 | |||
166 | /** |
||
167 | * Add one line variable definition comment. |
||
168 | * |
||
169 | * @param string $type Variable typeHint |
||
170 | * @param string $description Variable description |
||
171 | * @param string $name Variable name |
||
172 | * |
||
173 | *@return self Chaining |
||
174 | * @deprecated Use new generators logic |
||
175 | */ |
||
176 | public function commentVar($type, $description, $name = '') |
||
182 | |||
183 | /** |
||
184 | * Add multi-line comment. If array with one line is passed |
||
185 | * we create special syntax comment in one line, usually |
||
186 | * used for class variable definition in more compact form. |
||
187 | * |
||
188 | * @param array $lines Array of comments lines |
||
189 | * |
||
190 | * @deprecated Use new generators logic |
||
191 | * @return self Chaining |
||
192 | */ |
||
193 | public function multiComment(array $lines = array()) |
||
216 | |||
217 | /** |
||
218 | * Add variable definition with array merging. |
||
219 | * |
||
220 | * @param string $name Variable name |
||
221 | * @param array $value Array of key-value items for merging it to other array |
||
222 | * @param string $arrayName Name of array to merge to, if no is specified - $name is used |
||
223 | * |
||
224 | *@return self Chaining |
||
225 | * @deprecated Use new generators logic |
||
226 | */ |
||
227 | public function defArrayMerge($name, array $value, $arrayName = null) |
||
236 | |||
237 | /** |
||
238 | * Add variable definition. |
||
239 | * |
||
240 | * @param string $name Variable name |
||
241 | * @param mixed $value Variable default value |
||
242 | * @param string $after String to insert after variable definition |
||
243 | * @param string $end Closing part of variable definition |
||
244 | * @param string $quote Type of quote |
||
245 | * |
||
246 | *@return Generator Chaining |
||
247 | * @deprecated Use new generators logic |
||
248 | */ |
||
249 | public function defVar($name, $value = null, $after = ' = ', $end = ';', $quote = self::QUOTE_SINGLE) |
||
280 | |||
281 | /** |
||
282 | * Add string value definition. |
||
283 | * |
||
284 | * @param string $value String value to add |
||
285 | * @param string $tabs Tabs count |
||
286 | * @param string $quote Type of quote |
||
287 | * |
||
288 | * @deprecated Use new generators logic |
||
289 | * @return self Chaining |
||
290 | */ |
||
291 | public function stringValue($value, $tabs = null, $quote = self::QUOTE_SINGLE) |
||
295 | |||
296 | /** |
||
297 | * Add array values definition. |
||
298 | * |
||
299 | * @param array $items Array key-value pairs collection |
||
300 | * |
||
301 | * @deprecated Use new generators logic |
||
302 | * @return self Chaining |
||
303 | */ |
||
304 | public function arrayValue(array $items = array()) |
||
324 | |||
325 | /** |
||
326 | * Generate correct value. |
||
327 | * |
||
328 | * Metho handles arrays, numerics, strings and constants. |
||
329 | * |
||
330 | * @param mixed $value Value to put in generated code |
||
331 | * |
||
332 | * @deprecated Use new generators logic |
||
333 | * @return $this |
||
334 | */ |
||
335 | protected function defineValue($value) |
||
353 | |||
354 | /** |
||
355 | * Add trait definition. |
||
356 | * |
||
357 | * @param string $name Trait name |
||
358 | * |
||
359 | * @return self Chaining |
||
360 | * @deprecated Use new generators logic |
||
361 | */ |
||
362 | public function defTrait($name) |
||
382 | |||
383 | /** |
||
384 | * Close current class context. |
||
385 | * |
||
386 | * @return self Chaining |
||
387 | * @deprecated Use new generators logic |
||
388 | */ |
||
389 | public function endClass() |
||
398 | |||
399 | /** |
||
400 | * Add class definition. |
||
401 | * |
||
402 | * @param string $name Class name |
||
403 | * @param string $extends Parent class name |
||
404 | * @param array $implements Interfaces names collection |
||
405 | * |
||
406 | * @return self Chaining |
||
407 | * @deprecated Use new generators logic |
||
408 | */ |
||
409 | public function defClass($name, $extends = null, array $implements = array()) |
||
439 | |||
440 | /** |
||
441 | * Define if statement condition. |
||
442 | * |
||
443 | * @param string $condition Condition statement |
||
444 | * |
||
445 | * @return self Chaining |
||
446 | * @deprecated Use new generators logic |
||
447 | */ |
||
448 | public function defIfCondition($condition) |
||
457 | |||
458 | /** |
||
459 | * Define elseif statement condition. |
||
460 | * |
||
461 | * @param string $condition Condition statement |
||
462 | * |
||
463 | * @return self Chaining |
||
464 | * @deprecated Use new generators logic |
||
465 | */ |
||
466 | public function defElseIfCondition($condition) |
||
474 | |||
475 | /** |
||
476 | * Define else statement. |
||
477 | * |
||
478 | * @return self Chaining |
||
479 | * @deprecated Use new generators logic |
||
480 | */ |
||
481 | public function defElseCondition() |
||
489 | |||
490 | /** |
||
491 | * Close if condition statement. |
||
492 | * |
||
493 | * @return self Chaining |
||
494 | * @deprecated Use new generators logic |
||
495 | */ |
||
496 | public function endIfCondition() |
||
507 | |||
508 | /** |
||
509 | * Add class constant definition. |
||
510 | * |
||
511 | * @param string $name Constant name |
||
512 | * @param string $value Variable default value |
||
513 | * |
||
514 | * @return self Chaining |
||
515 | * @deprecated Use new generators logic |
||
516 | */ |
||
517 | public function defClassConst($name, $value) |
||
521 | |||
522 | /** |
||
523 | * Add class variable definition. |
||
524 | * |
||
525 | * @param string $name Variable name |
||
526 | * @param string $visibility Variable accessibility level |
||
527 | * @param mixed $value Variable default value |
||
528 | * |
||
529 | * @return self Chaining |
||
530 | * @deprecated Use new generators logic |
||
531 | */ |
||
532 | public function defClassVar($name, $visibility = 'public', $value = null) |
||
540 | |||
541 | /** |
||
542 | * Write file to disk |
||
543 | * |
||
544 | *@param string $name Path to file |
||
545 | * @param string $format Output file format |
||
546 | * |
||
547 | *@deprecated Use new generators logic |
||
548 | */ |
||
549 | public function write($name, $format = 'php') |
||
559 | |||
560 | /** |
||
561 | * Flush internal data and return it. |
||
562 | * |
||
563 | * @return string Current generated code |
||
564 | * @deprecated Use new generators logic |
||
565 | */ |
||
566 | public function flush() |
||
577 | |||
578 | /** |
||
579 | * @see self::defClassFunction with public visibility |
||
580 | * |
||
581 | * @return $this |
||
582 | * @deprecated Use new generators logic |
||
583 | */ |
||
584 | public function defPublicClassFunction(string $name, array $parameters = [], array $comments = [], $returnType = null) |
||
588 | |||
589 | /** |
||
590 | * Add class function definition. |
||
591 | * |
||
592 | * @param string $name Class function name |
||
593 | * @param string $visibility Class function visibility |
||
594 | * @param array $parameters Class function arguments |
||
595 | * @param array $comments Class function multi-line comments |
||
596 | * @param null $returnType Class function return type PHP7 |
||
597 | * |
||
598 | * @return $this |
||
599 | * @deprecated Use new generators logic |
||
600 | */ |
||
601 | public function defClassFunction(string $name, string $visibility = 'public', array $parameters = [], array $comments = [], $returnType = null) |
||
611 | |||
612 | /** |
||
613 | * Add function definition. |
||
614 | * |
||
615 | * @param string $name Function name |
||
616 | * @param array $parameters Collection of parameters $typeHint => $paramName |
||
617 | * @param string $prefix Function prefix |
||
618 | * @param array $comments Function multi-line comments |
||
619 | * @param string $returnType Function return type PHP7 |
||
620 | * |
||
621 | * @return Generator Chaining |
||
622 | * @deprecated Use new generators logic |
||
623 | */ |
||
624 | public function defFunction(string $name, array $parameters = [], string $prefix = '', array $comments = [], string $returnType = null) |
||
644 | |||
645 | /** |
||
646 | * @see self::defClassFunction with private visibility |
||
647 | * |
||
648 | * @return $this |
||
649 | * @deprecated Use new generators logic |
||
650 | */ |
||
651 | public function defPrivateClassFunction(string $name, array $parameters = [], array $comments = [], $returnType = null) |
||
655 | |||
656 | /** |
||
657 | * @see self::defClassFunction with protected visibility |
||
658 | * @deprecated Use new generators logic |
||
659 | * @return $this |
||
660 | */ |
||
661 | public function defProtectedClassFunction(string $name, array $parameters = [], array $comments = [], $returnType = null) |
||
665 | |||
666 | /** |
||
667 | * Close class function definition. |
||
668 | * @deprecated Use new generators logic |
||
669 | * @return $this Chaining |
||
670 | */ |
||
671 | public function endClassFunction() |
||
677 | |||
678 | /** |
||
679 | * Close current function context. |
||
680 | * @deprecated Use new generators logic |
||
681 | * @return self Chaining |
||
682 | */ |
||
683 | public function endFunction() |
||
689 | } |
||
690 | //[PHPCOMPRESSOR(remove,end)] |
||
691 |
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.