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 |
||
18 | class FqcnLocator extends Locator |
||
19 | { |
||
20 | |||
21 | /** |
||
22 | * @var array $FQCNs |
||
23 | */ |
||
24 | protected $FQCNs = array(); |
||
25 | |||
26 | /** |
||
27 | * @var array $namespaces |
||
28 | */ |
||
29 | protected $namespaces = array(); |
||
30 | |||
31 | |||
32 | /** |
||
33 | * @access protected |
||
34 | * @param string $namespace |
||
35 | * @param string $namespace_base_dir |
||
36 | * @throws InvalidDataTypeException |
||
37 | */ |
||
38 | protected function setNamespace($namespace, $namespace_base_dir) |
||
48 | |||
49 | |||
50 | /** |
||
51 | * @access public |
||
52 | * @return array |
||
53 | */ |
||
54 | public function getFQCNs() |
||
58 | |||
59 | |||
60 | /** |
||
61 | * @access public |
||
62 | * @return int |
||
63 | */ |
||
64 | public function count() |
||
68 | |||
69 | |||
70 | /** |
||
71 | * given a valid namespace, will find all files that match the provided mask |
||
72 | * |
||
73 | * @access public |
||
74 | * @param string|array $namespaces |
||
75 | * @return array |
||
76 | * @throws InvalidClassException |
||
77 | * @throws InvalidDataTypeException |
||
78 | */ |
||
79 | View Code Duplication | public function locate($namespaces) |
|
91 | |||
92 | |||
93 | /** |
||
94 | * given a partial namespace, will find all files in that folder |
||
95 | * ** PLZ NOTE ** |
||
96 | * This assumes that all files within the specified folder should be loaded |
||
97 | * |
||
98 | * @access protected |
||
99 | * @param string $partial_namespace |
||
100 | * @return array |
||
101 | * @throws InvalidClassException |
||
102 | * @throws InvalidDataTypeException |
||
103 | */ |
||
104 | protected function findFQCNsByNamespace($partial_namespace) |
||
131 | |||
132 | |||
133 | /** |
||
134 | * getDirectoryFromPartialNamespace |
||
135 | * |
||
136 | * @access protected |
||
137 | * @param string $partial_namespace almost fully qualified class name ? |
||
138 | * @return string |
||
139 | * @throws InvalidDataTypeException |
||
140 | * @throws InvalidClassException |
||
141 | */ |
||
142 | protected function getDirectoryFromPartialNamespace($partial_namespace) |
||
173 | } |
||
174 |