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 |
||
14 | final class DefinitionFinderTest extends TestCase |
||
15 | { |
||
16 | |||
17 | /** |
||
18 | * @var ContainerBuilder |
||
19 | */ |
||
20 | private $containerBuilder; |
||
21 | |||
22 | /** |
||
23 | * @var DefinitionFinder |
||
24 | */ |
||
25 | private $definitionFinder; |
||
26 | |||
27 | |||
28 | protected function setUp() |
||
33 | |||
34 | |||
35 | View Code Duplication | public function testAutowired() |
|
42 | |||
43 | |||
44 | View Code Duplication | public function testNonAutowired() |
|
52 | |||
53 | |||
54 | /** |
||
55 | * @expectedException \Zenify\DoctrineFilters\Exception\DefinitionForTypeNotFoundException |
||
56 | */ |
||
57 | public function testMissing() |
||
61 | |||
62 | } |
||
63 |
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.