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 ProjectVersion |
||
9 | { |
||
10 | private static $instance; |
||
11 | private $structure; |
||
12 | |||
13 | /** |
||
14 | * @return $this |
||
15 | */ |
||
16 | final public static function getInstance() |
||
24 | |||
25 | /** |
||
26 | * private construct - singleton |
||
27 | */ |
||
28 | private function __construct() |
||
31 | |||
32 | /** |
||
33 | * private clone - singleton |
||
34 | * @codeCoverageIgnore |
||
35 | */ |
||
36 | private function __clone() |
||
39 | |||
40 | /** |
||
41 | * Get version name |
||
42 | * @return string |
||
43 | */ |
||
44 | public function get() |
||
65 | |||
66 | /** |
||
67 | * @return string |
||
68 | * @codeCoverageIgnore |
||
69 | */ |
||
70 | protected function getGitHeadFilePath() |
||
74 | |||
75 | /** |
||
76 | * Retrieve environment variable |
||
77 | * @param string $name |
||
78 | * @return array|false|string |
||
79 | * @codeCoverageIgnore |
||
80 | */ |
||
81 | protected function getEnv($name) |
||
85 | |||
86 | public function name() |
||
90 | |||
91 | /** |
||
92 | * Return composer.json path to project |
||
93 | * @return string |
||
94 | */ |
||
95 | protected function getComposerPath() |
||
99 | |||
100 | /** |
||
101 | * Get composer file structure |
||
102 | * @return Object |
||
103 | */ |
||
104 | View Code Duplication | protected function getStructure() |
|
117 | } |
||
118 |