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 | 'etc.dir' => __DIR__ . '/etc', |
||
45 | 'src.dir' => __DIR__ . '/src', |
||
46 | 'dist.dir' => __DIR__ . '/dist', |
||
47 | 'vendor.dir' => __DIR__ . '/vendor', |
||
48 | 'target.dir' => __DIR__ . '/target', |
||
49 | 'webapp.name' => 'import-cli-simple', |
||
50 | 'webapp.version' => '1.0.0-alpha62' |
||
51 | ); |
||
52 | |||
53 | /** |
||
54 | * Run's the composer install command. |
||
55 | * |
||
56 | * @return void |
||
57 | */ |
||
58 | public function composerInstall() |
||
66 | |||
67 | /** |
||
68 | * Run's the composer update command. |
||
69 | * |
||
70 | * @return void |
||
71 | */ |
||
72 | public function composerUpdate() |
||
80 | |||
81 | /** |
||
82 | * Clean up the environment for a new build. |
||
83 | * |
||
84 | * @return void |
||
85 | */ |
||
86 | public function clean() |
||
90 | |||
91 | /** |
||
92 | * Prepare's the environment for a new build. |
||
93 | * |
||
94 | * @return void |
||
95 | */ |
||
96 | public function prepare() |
||
104 | |||
105 | /** |
||
106 | * Creates the a PHAR archive from the sources. |
||
107 | * |
||
108 | * @return void |
||
109 | */ |
||
110 | public function createPhar() |
||
195 | |||
196 | /** |
||
197 | * Run's the PHPMD. |
||
198 | * |
||
199 | * @return void |
||
200 | */ |
||
201 | View Code Duplication | public function runMd() |
|
214 | |||
215 | /** |
||
216 | * Run's the PHPCPD. |
||
217 | * |
||
218 | * @return void |
||
219 | */ |
||
220 | View Code Duplication | public function runCpd() |
|
233 | |||
234 | /** |
||
235 | * Run's the PHPCodeSniffer. |
||
236 | * |
||
237 | * @return void |
||
238 | */ |
||
239 | View Code Duplication | public function runCs() |
|
252 | |||
253 | /** |
||
254 | * Run's the PHPUnit tests. |
||
255 | * |
||
256 | * @return void |
||
257 | */ |
||
258 | public function runTests() |
||
259 | { |
||
260 | |||
261 | // run PHPUnit |
||
262 | $this->taskPHPUnit(sprintf('%s/bin/phpunit', $this->properties['vendor.dir'])) |
||
263 | ->configFile('phpunit.xml') |
||
264 | ->run(); |
||
265 | } |
||
266 | |||
267 | /** |
||
268 | * Raising the semver version number. |
||
269 | * |
||
270 | * @return void |
||
271 | */ |
||
272 | public function semver() |
||
278 | |||
279 | /** |
||
280 | * The complete build process. |
||
281 | * |
||
282 | * @return void |
||
283 | */ |
||
284 | public function build() |
||
293 | } |
||
294 |
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.