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 |
||
31 | final class Glob extends CompositeSpecification |
||
32 | { |
||
33 | /** @var string */ |
||
34 | private $regex; |
||
35 | |||
36 | /** |
||
37 | * The "static prefix" is the part of the glob up to the first wildcard "*". |
||
38 | * If the glob does not contain wildcards, the full glob is returned. |
||
39 | * |
||
40 | * @var string |
||
41 | */ |
||
42 | private $staticPrefix; |
||
43 | |||
44 | /** |
||
45 | * The "bounded prefix" is the part of the glob up to the first recursive wildcard "**". |
||
46 | * It is the longest prefix for which the number of directory segments in the partial match |
||
47 | * is known. If the glob does not contain the recursive wildcard "**", the full glob is returned. |
||
48 | * @var string |
||
49 | */ |
||
50 | private $boundedPrefix; |
||
51 | |||
52 | /** |
||
53 | * The "total prefix" is the part of the glob before the trailing catch-all wildcard sequence if the glob |
||
54 | * ends with one, otherwise null. It is needed for implementing the A-quantifier pruning hint. |
||
55 | * @var string |
||
56 | */ |
||
57 | private $totalPrefix; |
||
58 | |||
59 | public function __construct(string $glob) |
||
66 | |||
67 | /** |
||
68 | * @inheritDoc |
||
69 | */ |
||
70 | public function isSatisfiedBy(array $value) : bool |
||
84 | |||
85 | /** |
||
86 | * Returns the static prefix of a glob. |
||
87 | * |
||
88 | * The "static prefix" is the part of the glob up to the first wildcard "*". |
||
89 | * If the glob does not contain wildcards, the full glob is returned. |
||
90 | * |
||
91 | * @param string $glob The canonical glob. The glob should contain forward |
||
92 | * slashes as directory separators only. It must not |
||
93 | * contain any "." or ".." segments. |
||
94 | * |
||
95 | * @return string The static prefix of the glob. |
||
96 | * |
||
97 | * @psalm-pure |
||
98 | */ |
||
99 | private static function getStaticPrefix(string $glob) : string |
||
128 | |||
129 | private static function getBoundedPrefix(string $glob) : string |
||
153 | |||
154 | private static function getTotalPrefix(string $glob) : ?string |
||
162 | |||
163 | private static function scanBackslashSequence(string &$prefix, string $glob, int &$i) : void |
||
184 | |||
185 | /** |
||
186 | * @param string $glob |
||
187 | */ |
||
188 | private static function assertValidGlob(string $glob): void |
||
197 | |||
198 | /** |
||
199 | * Checks if the current position the glob is start of a Recursive directory wildcard |
||
200 | * |
||
201 | * @psalm-pure |
||
202 | */ |
||
203 | private static function isRecursiveWildcard(string $glob, int $i) : bool |
||
207 | |||
208 | /** |
||
209 | * Converts a glob to a regular expression. |
||
210 | * |
||
211 | * @param string $glob The canonical glob. The glob should contain forward |
||
212 | * slashes as directory separators only. It must not |
||
213 | * contain any "." or ".." segments. |
||
214 | * |
||
215 | * @return string The regular expression for matching the glob. |
||
216 | * |
||
217 | * @psalm-pure |
||
218 | */ |
||
219 | private static function toRegEx(string $glob) : string |
||
324 | |||
325 | /** @inheritDoc */ |
||
326 | public function canBeSatisfiedBySomethingBelow(array $value): bool |
||
343 | |||
344 | /** @inheritDoc */ |
||
345 | public function willBeSatisfiedByEverythingBelow(array $value): bool |
||
358 | } |
||
359 |