Complex classes like AdviceMatcher 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 AdviceMatcher, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 23 | class AdviceMatcher |
||
| 24 | { |
||
| 25 | /** |
||
| 26 | * Loader of aspects |
||
| 27 | * |
||
| 28 | * @var AspectLoader |
||
| 29 | */ |
||
| 30 | protected $loader; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Flag to enable/disable support of global function interception |
||
| 34 | * |
||
| 35 | * @var bool |
||
| 36 | */ |
||
| 37 | private $isInterceptFunctions; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Constructor |
||
| 41 | * |
||
| 42 | * @param AspectLoader $loader Instance of aspect loader |
||
| 43 | * @param bool $isInterceptFunctions Optional flag to enable function interception |
||
| 44 | */ |
||
| 45 | 4 | public function __construct(AspectLoader $loader, $isInterceptFunctions = false) |
|
| 51 | |||
| 52 | /** |
||
| 53 | * Returns list of function advices for namespace |
||
| 54 | * |
||
| 55 | * @param ReflectionFileNamespace $namespace |
||
| 56 | * @param array|Aop\Advisor[] $advisors List of advisor to match |
||
| 57 | * |
||
| 58 | * @return array |
||
| 59 | */ |
||
| 60 | public function getAdvicesForFunctions(ReflectionFileNamespace $namespace, array $advisors) |
||
| 84 | |||
| 85 | /** |
||
| 86 | * Return list of advices for class |
||
| 87 | * |
||
| 88 | * @param ReflectionClass $class Class to advise |
||
| 89 | * @param array|Aop\Advisor[] $advisors List of advisor to match |
||
| 90 | * |
||
| 91 | * @return array|Aop\Advice[] List of advices for class |
||
| 92 | */ |
||
| 93 | 3 | public function getAdvicesForClass(ReflectionClass $class, array $advisors) |
|
| 123 | |||
| 124 | /** |
||
| 125 | * Returns list of advices from advisor and point filter |
||
| 126 | * |
||
| 127 | * @param ReflectionClass $class Class to inject advices |
||
| 128 | * @param Aop\PointcutAdvisor $advisor Advisor for class |
||
| 129 | * @param string $advisorId Identifier of advisor |
||
| 130 | * @param Aop\PointFilter $filter Filter for points |
||
| 131 | * |
||
| 132 | * @return array |
||
| 133 | */ |
||
| 134 | 2 | private function getAdvicesFromAdvisor( |
|
| 186 | |||
| 187 | /** |
||
| 188 | * Returns list of introduction advices from advisor |
||
| 189 | * |
||
| 190 | * @param ReflectionClass $class Class to inject advices |
||
| 191 | * @param Aop\IntroductionAdvisor $advisor Advisor for class |
||
| 192 | * @param string $advisorId Identifier of advisor |
||
| 193 | * |
||
| 194 | * @return array |
||
| 195 | */ |
||
| 196 | private function getIntroductionFromAdvisor( |
||
| 213 | |||
| 214 | /** |
||
| 215 | * Returns list of function advices for specific namespace |
||
| 216 | * |
||
| 217 | * @param ReflectionFileNamespace $namespace |
||
| 218 | * @param Aop\PointcutAdvisor $advisor Advisor for class |
||
| 219 | * @param string $advisorId Identifier of advisor |
||
| 220 | * @param Aop\PointFilter $pointcut Filter for points |
||
| 221 | * |
||
| 222 | * @return array |
||
| 223 | */ |
||
| 224 | private function getFunctionAdvicesFromAdvisor( |
||
| 246 | } |
||
| 247 |