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 |
||
8 | class Options extends \BFW\Options |
||
9 | { |
||
10 | /** |
||
11 | * Search the root and vendor paths if they are not declared. |
||
12 | * |
||
13 | * @return $this |
||
14 | */ |
||
15 | public function searchPaths() |
||
29 | |||
30 | /** |
||
31 | * Check root and vendor path declared or found. |
||
32 | * |
||
33 | * @return $this |
||
34 | */ |
||
35 | public function checkPaths() |
||
59 | |||
60 | /** |
||
61 | * Find the vendor directory from the path of this file |
||
62 | * (In theory we are into) |
||
63 | * |
||
64 | * @return string |
||
65 | */ |
||
66 | protected function searchVendorDir() |
||
79 | |||
80 | /** |
||
81 | * Find the root directory from the vendor directory |
||
82 | * In theory of the vendor directory is on the root directory. |
||
83 | * If not, the user can define path for vendor and root directory. |
||
84 | * |
||
85 | * @return string |
||
86 | */ |
||
87 | protected function searchRootDir() |
||
91 | } |
||
92 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.