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 |
||
| 20 | class ConfigurationTest extends \PHPUnit_Framework_TestCase |
||
| 21 | { |
||
| 22 | /** |
||
| 23 | * @var Configuration |
||
| 24 | */ |
||
| 25 | private $configuration; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @var Processor |
||
| 29 | */ |
||
| 30 | private $processor; |
||
| 31 | |||
| 32 | protected function setUp() |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException |
||
| 40 | */ |
||
| 41 | public function testBaseUrlRequired() |
||
| 49 | |||
| 50 | View Code Duplication | public function testDefaultVersion() |
|
| 62 | |||
| 63 | /** |
||
| 64 | * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException |
||
| 65 | */ |
||
| 66 | public function testInvalidVersion() |
||
| 77 | |||
| 78 | /** |
||
| 79 | * @dataProvider validVersions |
||
| 80 | */ |
||
| 81 | View Code Duplication | public function testValidVersion($version) |
|
| 94 | |||
| 95 | private function processConfiguration(array $config) |
||
| 99 | |||
| 100 | public function validVersions() |
||
| 104 | } |
||
| 105 |
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.