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 |
||
38 | final class Glob extends CompositeSpecification |
||
39 | { |
||
40 | /** @var string */ |
||
41 | private $regex; |
||
42 | |||
43 | /** |
||
44 | * The "static prefix" is the part of the glob up to the first wildcard "*". |
||
45 | * If the glob does not contain wildcards, the full glob is returned. |
||
46 | * |
||
47 | * @var string |
||
48 | */ |
||
49 | private $staticPrefix; |
||
50 | |||
51 | /** |
||
52 | * The "bounded prefix" is the part of the glob up to the first recursive wildcard "**". |
||
53 | * It is the longest prefix for which the number of directory segments in the partial match |
||
54 | * is known. If the glob does not contain the recursive wildcard "**", the full glob is returned. |
||
55 | * |
||
56 | * @var string |
||
57 | */ |
||
58 | private $boundedPrefix; |
||
59 | |||
60 | /** |
||
61 | * The "total prefix" is the part of the glob before the trailing catch-all wildcard sequence if the glob |
||
62 | * ends with one, otherwise null. It is needed for implementing the A-quantifier pruning hint. |
||
63 | * |
||
64 | * @var string|null |
||
65 | */ |
||
66 | private $totalPrefix; |
||
67 | |||
68 | public function __construct(string $glob) |
||
75 | |||
76 | /** |
||
77 | * @inheritDoc |
||
78 | */ |
||
79 | public function isSatisfiedBy(array $value) : bool |
||
93 | |||
94 | /** |
||
95 | * Returns the static prefix of a glob. |
||
96 | * |
||
97 | * The "static prefix" is the part of the glob up to the first wildcard "*". |
||
98 | * If the glob does not contain wildcards, the full glob is returned. |
||
99 | * |
||
100 | * @param string $glob The canonical glob. The glob should contain forward |
||
101 | * slashes as directory separators only. It must not |
||
102 | * contain any "." or ".." segments. |
||
103 | * |
||
104 | * @return string The static prefix of the glob. |
||
105 | * |
||
106 | * @psalm-pure |
||
107 | */ |
||
108 | private static function getStaticPrefix(string $glob) : string |
||
139 | |||
140 | private static function getBoundedPrefix(string $glob) : string |
||
167 | |||
168 | private static function getTotalPrefix(string $glob) : ?string |
||
176 | |||
177 | /** |
||
178 | * @return mixed[] |
||
179 | * |
||
180 | * @psalm-return array{0: string, 1:int} |
||
181 | * @psalm-pure |
||
182 | */ |
||
183 | private static function scanBackslashSequence(string $glob, int $offset) : array |
||
207 | |||
208 | /** |
||
209 | * Asserts that glob is well formed |
||
210 | * |
||
211 | * @psalm-pure |
||
212 | */ |
||
213 | private static function assertValidGlob(string $glob) : void |
||
222 | |||
223 | /** |
||
224 | * Checks if the current position the glob is start of a Recursive directory wildcard |
||
225 | * |
||
226 | * @psalm-pure |
||
227 | */ |
||
228 | private static function isRecursiveWildcard(string $glob, int $i) : bool |
||
232 | |||
233 | /** |
||
234 | * Converts a glob to a regular expression. |
||
235 | * |
||
236 | * @param string $glob The canonical glob. The glob should contain forward |
||
237 | * slashes as directory separators only. It must not |
||
238 | * contain any "." or ".." segments. |
||
239 | * |
||
240 | * @return string The regular expression for matching the glob. |
||
241 | * |
||
242 | * @psalm-pure |
||
243 | */ |
||
244 | private static function toRegEx(string $glob) : string |
||
349 | |||
350 | /** @inheritDoc */ |
||
351 | public function canBeSatisfiedBySomethingBelow(array $value) : bool |
||
363 | |||
364 | /** @inheritDoc */ |
||
365 | public function willBeSatisfiedByEverythingBelow(array $value) : bool |
||
375 | } |
||
376 |
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.