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 |
||
| 23 | class ConfigEnvTest extends BaseConfigTest |
||
| 24 | { |
||
| 25 | /** |
||
| 26 | * @covers \Asm\Config\ConfigEnv::mergeEnvironments |
||
| 27 | * @covers \Asm\Config\ConfigEnv::__construct |
||
| 28 | * @return \Asm\Config\ConfigInterface |
||
| 29 | */ |
||
| 30 | View Code Duplication | public function testFactoryProd() |
|
| 44 | |||
| 45 | /** |
||
| 46 | * @covers \Asm\Config\ConfigEnv::mergeEnvironments |
||
| 47 | * @covers \Asm\Config\ConfigEnv::__construct |
||
| 48 | * @return \Asm\Config\ConfigInterface |
||
| 49 | */ |
||
| 50 | public function testFactoryProdWithoutFilecheck() |
||
| 65 | |||
| 66 | /** |
||
| 67 | * @covers \Asm\Config\ConfigEnv::mergeEnvironments |
||
| 68 | * @covers \Asm\Config\ConfigEnv::__construct |
||
| 69 | * @return \Asm\Config\ConfigInterface |
||
| 70 | */ |
||
| 71 | public function testFactoryEnv() |
||
| 86 | |||
| 87 | /** |
||
| 88 | * @depends testFactoryEnv |
||
| 89 | * @param ConfigEnv $config |
||
| 90 | */ |
||
| 91 | public function testConfigMerge(ConfigEnv $config) |
||
| 95 | |||
| 96 | |||
| 97 | /** |
||
| 98 | * @depends testFactoryEnv |
||
| 99 | * @param ConfigEnv $config |
||
| 100 | */ |
||
| 101 | public function testConfigInclude(ConfigEnv $config) |
||
| 111 | |||
| 112 | /** |
||
| 113 | * @depends testFactoryEnv |
||
| 114 | * @param ConfigEnv $config |
||
| 115 | */ |
||
| 116 | public function testConfigDefaultNode(ConfigEnv $config) |
||
| 123 | } |
||
| 124 |
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.