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 |
||
36 | class RoboFile extends \Robo\Tasks |
||
|
|||
37 | { |
||
38 | |||
39 | /** |
||
40 | * The build properties. |
||
41 | * |
||
42 | * @var array |
||
43 | */ |
||
44 | protected $properties = array( |
||
45 | 'base.dir' => __DIR__, |
||
46 | 'src.dir' => __DIR__ . '/src', |
||
47 | 'dist.dir' => __DIR__ . '/dist', |
||
48 | 'vendor.dir' => __DIR__ . '/vendor', |
||
49 | 'target.dir' => __DIR__ . '/target', |
||
50 | 'webapp.name' => 'import-cli-simple', |
||
51 | 'webapp.version' => '1.0.0-alpha5' |
||
52 | ); |
||
53 | |||
54 | /** |
||
55 | * Run's the composer install command. |
||
56 | * |
||
57 | * @return void |
||
58 | */ |
||
59 | public function composerInstall() |
||
67 | |||
68 | /** |
||
69 | * Run's the composer update command. |
||
70 | * |
||
71 | * @return void |
||
72 | */ |
||
73 | public function composerUpdate() |
||
81 | |||
82 | /** |
||
83 | * Clean up the environment for a new build. |
||
84 | * |
||
85 | * @return void |
||
86 | */ |
||
87 | public function clean() |
||
91 | |||
92 | /** |
||
93 | * Prepare's the environment for a new build. |
||
94 | * |
||
95 | * @return void |
||
96 | */ |
||
97 | public function prepare() |
||
105 | |||
106 | /** |
||
107 | * Run's the PHPMD. |
||
108 | * |
||
109 | * @return void |
||
110 | */ |
||
111 | View Code Duplication | public function runMd() |
|
124 | |||
125 | /** |
||
126 | * Run's the PHPCPD. |
||
127 | * |
||
128 | * @return void |
||
129 | */ |
||
130 | View Code Duplication | public function runCpd() |
|
143 | |||
144 | /** |
||
145 | * Run's the PHPCodeSniffer. |
||
146 | * |
||
147 | * @return void |
||
148 | */ |
||
149 | View Code Duplication | public function runCs() |
|
162 | |||
163 | /** |
||
164 | * Run's the PHPUnit tests. |
||
165 | * |
||
166 | * @return void |
||
167 | */ |
||
168 | public function runTests() |
||
169 | { |
||
170 | |||
171 | // run PHPUnit |
||
172 | $this->taskPHPUnit(sprintf('%s/bin/phpunit', $this->properties['vendor.dir'])) |
||
173 | ->configFile('phpunit.xml') |
||
174 | ->run(); |
||
175 | } |
||
176 | |||
177 | /** |
||
178 | * The complete build process. |
||
179 | * |
||
180 | * @return void |
||
181 | */ |
||
182 | public function build() |
||
191 | } |
||
192 |
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.