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 |
||
138 | |||
139 | private static function getBoundedPrefix(string $glob) : string |
||
165 | |||
166 | private static function getTotalPrefix(string $glob) : ?string |
||
174 | |||
175 | /** |
||
176 | * @return mixed[] |
||
177 | * |
||
178 | * @psalm-return array{0: string, 1:int} |
||
179 | * @psalm-pure |
||
180 | */ |
||
181 | private static function scanBackslashSequence(string $prefix, string $glob, int $i) : array |
||
204 | |||
205 | /** |
||
206 | * Asserts that glob is well formed |
||
207 | * |
||
208 | * @psalm-pure |
||
209 | */ |
||
210 | private static function assertValidGlob(string $glob) : void |
||
219 | |||
220 | /** |
||
221 | * Checks if the current position the glob is start of a Recursive directory wildcard |
||
222 | * |
||
223 | * @psalm-pure |
||
224 | */ |
||
225 | private static function isRecursiveWildcard(string $glob, int $i) : bool |
||
229 | |||
230 | /** |
||
231 | * Converts a glob to a regular expression. |
||
232 | * |
||
233 | * @param string $glob The canonical glob. The glob should contain forward |
||
234 | * slashes as directory separators only. It must not |
||
235 | * contain any "." or ".." segments. |
||
236 | * |
||
237 | * @return string The regular expression for matching the glob. |
||
238 | * |
||
239 | * @psalm-pure |
||
240 | */ |
||
241 | private static function toRegEx(string $glob) : string |
||
346 | |||
347 | /** @inheritDoc */ |
||
348 | public function canBeSatisfiedBySomethingBelow(array $value) : bool |
||
360 | |||
361 | /** @inheritDoc */ |
||
362 | public function willBeSatisfiedByEverythingBelow(array $value) : bool |
||
372 | } |
||
373 |
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.