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 OPCacheStatusTest extends \PHPUnit_Framework_TestCase |
|
|
|||
9 | { |
||
10 | /** |
||
11 | * @var OPCacheStatus |
||
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 OPCacheStatus::getStatusData |
||
33 | * @todo Implement testGetStatusData(). |
||
34 | */ |
||
35 | public function testGetStatusData() |
||
42 | |||
43 | /** |
||
44 | * @covers OPCacheStatus::getCurrentStatus |
||
45 | * @todo Implement testGetCurrentStatus(). |
||
46 | */ |
||
47 | public function testGetCurrentStatus() |
||
54 | |||
55 | /** |
||
56 | * @covers OPCacheStatus::getMemoryInfo |
||
57 | * @todo Implement testGetMemoryInfo(). |
||
58 | */ |
||
59 | public function testGetMemoryInfo() |
||
66 | |||
67 | /** |
||
68 | * @covers OPCacheStatus::getMemoryUsage |
||
69 | * @todo Implement testGetMemoryUsage(). |
||
70 | */ |
||
71 | public function testGetMemoryUsage() |
||
78 | |||
79 | /** |
||
80 | * @covers OPCacheStatus::getStatistics |
||
81 | * @todo Implement testGetStatistics(). |
||
82 | */ |
||
83 | public function testGetStatistics() |
||
90 | |||
91 | /** |
||
92 | * @covers OPCacheStatus::getScripts |
||
93 | * @todo Implement testGetScripts(). |
||
94 | */ |
||
95 | public function testGetScripts() |
||
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.