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 |
||
8 | View Code Duplication | class OPCacheConfigurationTest extends \PHPUnit_Framework_TestCase |
|
|
|||
9 | { |
||
10 | /** |
||
11 | * @var OPCacheConfiguration |
||
12 | */ |
||
13 | protected $object; |
||
14 | |||
15 | /** |
||
16 | * Sets up the fixture, for example, opens a network connection. |
||
17 | * This method is called before a test is executed. |
||
18 | */ |
||
19 | protected function setUp() |
||
22 | |||
23 | /** |
||
24 | * Tears down the fixture, for example, closes a network connection. |
||
25 | * This method is called after a test is executed. |
||
26 | */ |
||
27 | protected function tearDown() |
||
30 | |||
31 | /** |
||
32 | * @covers OPCacheConfiguration::getDirectives |
||
33 | * @todo Implement testGetDirectives(). |
||
34 | */ |
||
35 | public function testGetDirectives() |
||
42 | |||
43 | /** |
||
44 | * @covers OPCacheConfiguration::getDirective |
||
45 | * @todo Implement testGetDirective(). |
||
46 | */ |
||
47 | public function testGetDirective() |
||
54 | |||
55 | /** |
||
56 | * @covers OPCacheConfiguration::getDirectiveKeys |
||
57 | * @todo Implement testGetDirectiveKeys(). |
||
58 | */ |
||
59 | public function testGetDirectiveKeys() |
||
66 | |||
67 | /** |
||
68 | * @covers OPCacheConfiguration::getBlacklist |
||
69 | * @todo Implement testGetBlacklist(). |
||
70 | */ |
||
71 | public function testGetBlacklist() |
||
78 | |||
79 | /** |
||
80 | * @covers OPCacheConfiguration::getVersion |
||
81 | * @todo Implement testGetVersion(). |
||
82 | */ |
||
83 | public function testGetVersion() |
||
90 | |||
91 | /** |
||
92 | * @covers OPCacheConfiguration::checkDirectives |
||
93 | * @todo Implement testCheckDirectives(). |
||
94 | */ |
||
95 | public function testCheckDirectives() |
||
102 | } |
||
103 |
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.