Complex classes like AbstractProxy 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 AbstractProxy, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 21 | abstract class AbstractProxy |
||
| 22 | { |
||
| 23 | |||
| 24 | /** |
||
| 25 | * Indent for source code |
||
| 26 | * |
||
| 27 | * @var int |
||
| 28 | */ |
||
| 29 | protected $indent = 4; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * List of advices that are used for generation of child |
||
| 33 | * |
||
| 34 | * @var array |
||
| 35 | */ |
||
| 36 | protected $advices = []; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * PHP expression string for accessing LSB information |
||
| 40 | * |
||
| 41 | * @var string |
||
| 42 | */ |
||
| 43 | protected static $staticLsbExpression = 'static::class'; |
||
| 44 | |||
| 45 | /** |
||
| 46 | * Constructs an abstract proxy class |
||
| 47 | * |
||
| 48 | * @param array $advices List of advices |
||
| 49 | */ |
||
| 50 | public function __construct(array $advices = []) |
||
| 54 | |||
| 55 | /** |
||
| 56 | * Returns text representation of class |
||
| 57 | * |
||
| 58 | * @return string |
||
| 59 | */ |
||
| 60 | abstract public function __toString(); |
||
| 61 | |||
| 62 | /** |
||
| 63 | * Indent block of code |
||
| 64 | * |
||
| 65 | * @param string $text Non-indented text |
||
| 66 | * |
||
| 67 | * @return string Indented text |
||
| 68 | */ |
||
| 69 | protected function indent($text) |
||
| 78 | |||
| 79 | /** |
||
| 80 | * Returns list of string representation of parameters |
||
| 81 | * |
||
| 82 | * @param array|ReflectionParameter[] $parameters List of parameters |
||
| 83 | * |
||
| 84 | * @return array |
||
| 85 | */ |
||
| 86 | protected function getParameters(array $parameters) |
||
| 95 | |||
| 96 | /** |
||
| 97 | * Return string representation of parameter |
||
| 98 | * |
||
| 99 | * @param ReflectionParameter $parameter Reflection parameter |
||
| 100 | * |
||
| 101 | * @return string |
||
| 102 | */ |
||
| 103 | protected function getParameterCode(ReflectionParameter $parameter) |
||
| 140 | |||
| 141 | /** |
||
| 142 | * Replace concrete advices with list of ids |
||
| 143 | * |
||
| 144 | * @param array $advices |
||
| 145 | * |
||
| 146 | * @return array flatten list of advices |
||
| 147 | */ |
||
| 148 | private function flattenAdvices(array $advices) |
||
| 161 | |||
| 162 | /** |
||
| 163 | * Prepares a line with args from the method definition |
||
| 164 | * |
||
| 165 | * @param ReflectionFunctionAbstract $functionLike |
||
| 166 | * |
||
| 167 | * @return string |
||
| 168 | */ |
||
| 169 | protected function prepareArgsLine(ReflectionFunctionAbstract $functionLike) |
||
| 197 | |||
| 198 | /** |
||
| 199 | * Creates a function code from Reflection |
||
| 200 | * |
||
| 201 | * @param ReflectionFunctionAbstract $functionLike Reflection for method |
||
| 202 | * @param string $body Body of method |
||
| 203 | * |
||
| 204 | * @return string |
||
| 205 | */ |
||
| 206 | protected function getOverriddenFunction(ReflectionFunctionAbstract $functionLike, $body) |
||
| 238 | } |
||
| 239 |