Complex classes like Glob 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 Glob, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
30 | final class Glob extends CompositeSpecification |
||
31 | { |
||
32 | /** @var string */ |
||
33 | private $regex; |
||
34 | |||
35 | /** |
||
36 | * The "static prefix" is the part of the glob up to the first wildcard "*". |
||
37 | * If the glob does not contain wildcards, the full glob is returned. |
||
38 | * |
||
39 | * @var string |
||
40 | */ |
||
41 | private $staticPrefix; |
||
42 | |||
43 | public function __construct(string $glob) |
||
48 | |||
49 | /** |
||
50 | * @inheritDoc |
||
51 | */ |
||
52 | public function isSatisfiedBy(array $value) : bool |
||
66 | |||
67 | /** |
||
68 | * Returns the static prefix of a glob. |
||
69 | * |
||
70 | * The "static prefix" is the part of the glob up to the first wildcard "*". |
||
71 | * If the glob does not contain wildcards, the full glob is returned. |
||
72 | * |
||
73 | * @param string $glob The canonical glob. The glob should contain forward |
||
74 | * slashes as directory separators only. It must not |
||
75 | * contain any "." or ".." segments. |
||
76 | * |
||
77 | * @return string The static prefix of the glob. |
||
78 | * |
||
79 | * @psalm-pure |
||
80 | */ |
||
81 | private static function getStaticPrefix(string $glob) : string |
||
134 | |||
135 | /** |
||
136 | * Checks if the current position the glob is start of a Recursive directory wildcard |
||
137 | * |
||
138 | * @psalm-pure |
||
139 | */ |
||
140 | private static function isRecursiveWildcard(string $glob, int $i) : bool |
||
144 | |||
145 | /** |
||
146 | * Converts a glob to a regular expression. |
||
147 | * |
||
148 | * @param string $glob The canonical glob. The glob should contain forward |
||
149 | * slashes as directory separators only. It must not |
||
150 | * contain any "." or ".." segments. |
||
151 | * |
||
152 | * @return string The regular expression for matching the glob. |
||
153 | * |
||
154 | * @psalm-pure |
||
155 | */ |
||
156 | private static function toRegEx(string $glob) : string |
||
261 | } |
||
262 |