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 |
||
34 | class RoboFile extends \Robo\Tasks |
||
|
|||
35 | { |
||
36 | |||
37 | /** |
||
38 | * The build properties. |
||
39 | * |
||
40 | * @var array |
||
41 | */ |
||
42 | protected $properties = array( |
||
43 | 'base.dir' => __DIR__, |
||
44 | 'src.dir' => __DIR__ . '/src', |
||
45 | 'dist.dir' => __DIR__ . '/dist', |
||
46 | 'vendor.dir' => __DIR__ . '/vendor', |
||
47 | 'target.dir' => __DIR__ . '/target', |
||
48 | 'webapp.name' => 'import-cli-simple', |
||
49 | 'webapp.version' => '1.0.0-alpha4' |
||
50 | ); |
||
51 | |||
52 | /** |
||
53 | * Run's the composer install command. |
||
54 | * |
||
55 | * @return void |
||
56 | */ |
||
57 | public function composerInstall() |
||
65 | |||
66 | /** |
||
67 | * Run's the composer update command. |
||
68 | * |
||
69 | * @return void |
||
70 | */ |
||
71 | public function composerUpdate() |
||
79 | |||
80 | /** |
||
81 | * Clean up the environment for a new build. |
||
82 | * |
||
83 | * @return void |
||
84 | */ |
||
85 | public function clean() |
||
89 | |||
90 | /** |
||
91 | * Prepare's the environment for a new build. |
||
92 | * |
||
93 | * @return void |
||
94 | */ |
||
95 | public function prepare() |
||
103 | |||
104 | /** |
||
105 | * Creates the a PHAR archive from the sources. |
||
106 | * |
||
107 | * @return void |
||
108 | */ |
||
109 | public function createPhar() |
||
159 | |||
160 | /** |
||
161 | * Run's the PHPMD. |
||
162 | * |
||
163 | * @return void |
||
164 | */ |
||
165 | View Code Duplication | public function runMd() |
|
178 | |||
179 | /** |
||
180 | * Run's the PHPCPD. |
||
181 | * |
||
182 | * @return void |
||
183 | */ |
||
184 | View Code Duplication | public function runCpd() |
|
197 | |||
198 | /** |
||
199 | * Run's the PHPCodeSniffer. |
||
200 | * |
||
201 | * @return void |
||
202 | */ |
||
203 | View Code Duplication | public function runCs() |
|
216 | |||
217 | /** |
||
218 | * Run's the PHPUnit tests. |
||
219 | * |
||
220 | * @return void |
||
221 | */ |
||
222 | public function runTests() |
||
223 | { |
||
224 | |||
225 | // run PHPUnit |
||
226 | $this->taskPHPUnit(sprintf('%s/bin/phpunit', $this->properties['vendor.dir'])) |
||
227 | ->configFile('phpunit.xml') |
||
228 | ->run(); |
||
229 | } |
||
230 | |||
231 | /** |
||
232 | * The complete build process. |
||
233 | * |
||
234 | * @return void |
||
235 | */ |
||
236 | public function build() |
||
245 | } |
||
246 |
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.