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 |
||
18 | final class DefinedSymbolCollectorFunctionalTest extends \PHPUnit_Framework_TestCase |
||
19 | { |
||
20 | /** |
||
21 | * @var DefinedSymbolCollector |
||
22 | */ |
||
23 | private $collector; |
||
24 | |||
25 | /** |
||
26 | * @var Parser |
||
27 | */ |
||
28 | private $parser; |
||
29 | |||
30 | /** |
||
31 | * @var NodeTraverserInterface |
||
32 | */ |
||
33 | private $traverser; |
||
34 | |||
35 | /** |
||
36 | * {@inheritDoc} |
||
37 | */ |
||
38 | View Code Duplication | protected function setUp() |
|
47 | |||
48 | public function testWillCollectSymbolsDefinedInThisFile() |
||
57 | |||
58 | public function testWillCollectFunctionDefinition() |
||
67 | |||
68 | public function testWillCollectNamespacedFunctionDefinition() |
||
77 | |||
78 | public function testWillCollectConstDefinition() |
||
87 | |||
88 | public function testWillCollectNamespacedConstDefinition() |
||
97 | |||
98 | private function traverseStringAST(string $phpSource) : array |
||
102 | |||
103 | private function traverseClassAST(string $className) : array |
||
111 | |||
112 | private static function assertSameCollectedSymbols(array $expected, array $actual) |
||
116 | } |
||
117 |
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.