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 |
||
| 9 | class PHPUnitBinFile |
||
| 10 | { |
||
| 11 | // I'm using Paraunit as a vendor package |
||
| 12 | const PHPUNIT_RELPATH_FOR_VENDOR = '/../../../../../phpunit/phpunit/phpunit'; |
||
| 13 | // I'm using Paraunit standalone (developing) |
||
| 14 | const PHPUNIT_RELPATH_FOR_STANDALONE = '/../../../vendor/phpunit/phpunit/phpunit'; |
||
| 15 | |||
| 16 | /** @var string Realpath to PHPUnit bin location */ |
||
| 17 | private $phpUnitBin; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * PHPUnitBinFile constructor. |
||
| 21 | * @throws \RuntimeException |
||
| 22 | */ |
||
| 23 | 12 | public function __construct() |
|
| 47 | |||
| 48 | /** |
||
| 49 | * @return string |
||
| 50 | */ |
||
| 51 | 12 | public function getPhpUnitBin() |
|
| 55 | } |
||
| 56 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.