Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php |
||
20 | final class Configuration |
||
21 | { |
||
22 | /** @internal */ |
||
23 | const FINDER_KEYWORD = 'finders'; |
||
24 | |||
25 | /** @internal */ |
||
26 | const PATCHERS_KEYWORD = 'patchers'; |
||
27 | |||
28 | /** @internal */ |
||
29 | const GLOBAL_NAMESPACE_KEYWORD = 'global_namespace_whitelist'; |
||
30 | |||
31 | /** @internal */ |
||
32 | const KEYWORDS = [ |
||
33 | self::FINDER_KEYWORD, |
||
34 | self::PATCHERS_KEYWORD, |
||
35 | self::GLOBAL_NAMESPACE_KEYWORD, |
||
36 | ]; |
||
37 | |||
38 | private $path; |
||
39 | private $patchers; |
||
40 | private $finders; |
||
41 | private $globalNamespaceWhitelisters; |
||
42 | |||
43 | /** |
||
44 | * @param string|null $path Absolute path to the configuration file loaded |
||
45 | * @param Finder[] $finders |
||
46 | * @param callable[] $patchers List of closures which can alter the content of the files being |
||
47 | * scoped |
||
48 | * @param callable[]|string[] $globalNamespace List of class names from the global namespace that should be scoped |
||
49 | * or closures filtering if the class should be scoped or not |
||
50 | */ |
||
51 | private function __construct(string $path = null, array $finders, array $patchers, array $globalNamespace) |
||
58 | |||
59 | /** |
||
60 | * @param string|null $path Absolute path to the configuration file. |
||
61 | * |
||
62 | * @return self |
||
63 | */ |
||
64 | public static function load(string $path = null): self |
||
89 | |||
90 | public function getPath(): string |
||
94 | |||
95 | /** |
||
96 | * @return Finder[] |
||
97 | */ |
||
98 | public function getFinders(): array |
||
102 | |||
103 | /** |
||
104 | * @return callable[] |
||
105 | */ |
||
106 | public function getPatchers() |
||
110 | |||
111 | /** |
||
112 | * @return callable[]|string[] |
||
113 | */ |
||
114 | public function getGlobalNamespaceWhitelisters() |
||
118 | |||
119 | private static function validateConfigKeys(array $config) |
||
126 | |||
127 | private static function validateConfigKey(string $key) |
||
138 | |||
139 | private static function retrieveFinders(array $config): array |
||
173 | |||
174 | View Code Duplication | private static function retrievePatchers(array $config): array |
|
206 | |||
207 | View Code Duplication | private static function retrieveGlobalNamespaceWhitelisters(array $config): array |
|
240 | } |
||
241 |