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 |
||
7 | class Path_Processor { |
||
8 | /** |
||
9 | * Given a path this will replace any of the path constants with a token to represent it. |
||
10 | * |
||
11 | * @param string $path The path we want to process. |
||
12 | * @return string The tokenized path. |
||
13 | */ |
||
14 | View Code Duplication | public function tokenize_path_constants( $path ) { |
|
29 | |||
30 | /** |
||
31 | * Given a path this will replace any of the path constant tokens with the expanded path. |
||
32 | * |
||
33 | * @param string $tokenized_path The path we want to process. |
||
34 | * @return string The expanded path. |
||
35 | */ |
||
36 | View Code Duplication | public function untokenize_path_constants( $tokenized_path ) { |
|
53 | |||
54 | /** |
||
55 | * Given a file and an array of places it might be, this will find the absolute path and return it. |
||
56 | * |
||
57 | * @param string $file The plugin or theme file to resolve. |
||
58 | * @param array $directories_to_check The directories we should check for the file if it isn't an absolute path. |
||
59 | * @return string|false Returns the absolute path to the directory, otherwise false. |
||
60 | */ |
||
61 | public function find_directory_with_autoloader( $file, $directories_to_check ) { |
||
83 | |||
84 | /** |
||
85 | * Fetches an array of normalized paths keyed by the constant they came from. |
||
86 | * |
||
87 | * @return string[] The normalized paths keyed by the constant. |
||
88 | */ |
||
89 | private function get_normalized_constants() { |
||
112 | |||
113 | /** |
||
114 | * Indicates whether or not a path is absolute. |
||
115 | * |
||
116 | * @param string $path The path to check. |
||
117 | * @return bool True if the path is absolute, otherwise false. |
||
118 | */ |
||
119 | private function is_absolute_path( $path ) { |
||
132 | |||
133 | /** |
||
134 | * Given a file and a list of directories to check, this method will try to figure out |
||
135 | * the absolute path to the file in question. |
||
136 | * |
||
137 | * @param string $file The plugin or theme file to resolve. |
||
138 | * @param array $directories_to_check The directories we should check for the file if it isn't an absolute path. |
||
139 | * @return string|null The absolute path to the plugin directory, otherwise null. |
||
140 | */ |
||
141 | private function find_plugin_directory( $file, $directories_to_check ) { |
||
157 | } |
||
158 |