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 |
||
21 | class OrbitaleCmsExtensionTest extends TestCase |
||
22 | { |
||
23 | /** |
||
24 | * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException |
||
25 | * @expectedExceptionMessage Page class must be a valid class extending Orbitale\Bundle\CmsBundle\Entity\Page. "inexistent_page_class" given. |
||
26 | */ |
||
27 | View Code Duplication | public function testInexistentPageClass() |
|
40 | |||
41 | /** |
||
42 | * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException |
||
43 | * @expectedExceptionMessage Category class must be a valid class extending Orbitale\Bundle\CmsBundle\Entity\Category. "inexistent_category_class" given. |
||
44 | */ |
||
45 | View Code Duplication | public function testInexistentCategoryClass() |
|
58 | |||
59 | /** |
||
60 | * @dataProvider provideYamlConfiguration |
||
61 | * |
||
62 | * @param $config |
||
63 | * @param $expected |
||
64 | */ |
||
65 | public function testYamlConfiguration($config, $expected) |
||
79 | |||
80 | public function provideYamlConfiguration(): array |
||
101 | } |
||
102 |
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.