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 |
||
11 | class Installer |
||
|
|||
12 | { |
||
13 | const TEST_FOLDER = 'tests'; |
||
14 | |||
15 | private $silent = false; |
||
16 | |||
17 | public function __construct($silent = false) |
||
21 | |||
22 | public function install($app = 'application') |
||
23 | { |
||
24 | $this->recursiveCopy( |
||
25 | dirname(__FILE__) . '/application/tests', |
||
26 | $app . '/' . static::TEST_FOLDER |
||
27 | ); |
||
28 | $this->fixPath($app); |
||
29 | } |
||
30 | |||
31 | /** |
||
32 | * Fix paths in Bootstrap.php |
||
33 | */ |
||
34 | private function fixPath($app = 'application') |
||
92 | |||
93 | public function update($app = 'application') |
||
94 | { |
||
95 | $target_dir = $app . '/' . static::TEST_FOLDER . '/_ci_phpunit_test'; |
||
96 | $this->recursiveUnlink($target_dir); |
||
97 | $this->recursiveCopy( |
||
98 | dirname(__FILE__) . '/application/tests/_ci_phpunit_test', |
||
99 | $target_dir |
||
100 | ); |
||
101 | } |
||
102 | |||
103 | /** |
||
104 | * Recursive Copy |
||
105 | * |
||
106 | * @param string $src |
||
107 | * @param string $dst |
||
108 | */ |
||
109 | private function recursiveCopy($src, $dst) |
||
131 | |||
132 | /** |
||
133 | * Recursive Unlink |
||
134 | * |
||
135 | * @param string $dir |
||
136 | */ |
||
137 | View Code Duplication | private function recursiveUnlink($dir) |
|
154 | } |
||
155 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.