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 |
||
| 35 | class RoboFile extends \Robo\Tasks |
||
| 36 | { |
||
| 37 | |||
| 38 | /** |
||
| 39 | * The build properties. |
||
| 40 | * |
||
| 41 | * @var array |
||
| 42 | */ |
||
| 43 | protected $properties = array( |
||
| 44 | 'base.dir' => __DIR__, |
||
| 45 | 'src.dir' => __DIR__ . '/src', |
||
| 46 | 'dist.dir' => __DIR__ . '/dist', |
||
| 47 | 'vendor.dir' => __DIR__ . '/vendor', |
||
| 48 | 'target.dir' => __DIR__ . '/target' |
||
| 49 | ); |
||
| 50 | |||
| 51 | /** |
||
| 52 | * Run's the composer install command. |
||
| 53 | * |
||
| 54 | * @return \Robo\Result The result |
||
| 55 | */ |
||
| 56 | public function composerInstall() |
||
| 64 | |||
| 65 | /** |
||
| 66 | * Run's the composer update command. |
||
| 67 | * |
||
| 68 | * @return \Robo\Result The result |
||
| 69 | */ |
||
| 70 | public function composerUpdate() |
||
| 78 | |||
| 79 | /** |
||
| 80 | * Clean up the environment for a new build. |
||
| 81 | * |
||
| 82 | * @return \Robo\Result The result |
||
| 83 | */ |
||
| 84 | public function clean() |
||
| 88 | |||
| 89 | /** |
||
| 90 | * Prepare's the environment for a new build. |
||
| 91 | * |
||
| 92 | * @return \Robo\Result The result |
||
| 93 | */ |
||
| 94 | public function prepare() |
||
| 102 | |||
| 103 | /** |
||
| 104 | * Run's the PHPMD. |
||
| 105 | * |
||
| 106 | * @return \Robo\Result The result |
||
| 107 | */ |
||
| 108 | View Code Duplication | public function runMd() |
|
| 121 | |||
| 122 | /** |
||
| 123 | * Run's the PHPCPD. |
||
| 124 | * |
||
| 125 | * @return \Robo\Result The result |
||
| 126 | */ |
||
| 127 | View Code Duplication | public function runCpd() |
|
| 140 | |||
| 141 | /** |
||
| 142 | * Run's the PHPCodeSniffer. |
||
| 143 | * |
||
| 144 | * @return \Robo\Result The result |
||
| 145 | */ |
||
| 146 | View Code Duplication | public function runCs() |
|
| 159 | |||
| 160 | /** |
||
| 161 | * Run's the PHPUnit tests. |
||
| 162 | * |
||
| 163 | * @return \Robo\Result The result |
||
| 164 | */ |
||
| 165 | public function runTests() |
||
| 166 | { |
||
| 167 | |||
| 168 | // run PHPUnit |
||
| 169 | return $this->taskPHPUnit(sprintf('%s/bin/phpunit', $this->properties['vendor.dir'])) |
||
| 170 | ->configFile('phpunit.xml') |
||
| 171 | ->run(); |
||
| 172 | } |
||
| 173 | |||
| 174 | /** |
||
| 175 | * The complete build process. |
||
| 176 | * |
||
| 177 | * @return void |
||
| 178 | */ |
||
| 179 | public function build() |
||
| 193 | } |
||
| 194 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: