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 |
||
10 | class AbstractConfigTest extends \PHPUnit_Framework_TestCase |
||
11 | { |
||
12 | /** |
||
13 | * @var AbstractConfig |
||
14 | */ |
||
15 | protected $object; |
||
16 | |||
17 | View Code Duplication | public function setUp() |
|
36 | |||
37 | public function tearDown() |
||
41 | |||
42 | public function getConfigFileContent() |
||
52 | |||
53 | public function getConfigArray() |
||
59 | |||
60 | /** |
||
61 | * @covers Koch\Config\Adapter\PHP::read |
||
62 | * @covers Koch\Config\AbstractConfig::toArray |
||
63 | */ |
||
64 | public function testToArray() |
||
73 | |||
74 | /** |
||
75 | * @covers Koch\Config\AbstractConfig::merge |
||
76 | */ |
||
77 | public function testMerge() |
||
89 | |||
90 | /** |
||
91 | * @covers Koch\Config\AbstractConfig::getConfigValue |
||
92 | */ |
||
93 | public function testGetConfigValue() |
||
115 | |||
116 | /** |
||
117 | * @covers Koch\Config\AbstractConfig::__get |
||
118 | */ |
||
119 | public function test__get() |
||
127 | |||
128 | /** |
||
129 | * @covers Koch\Config\AbstractConfig::__set |
||
130 | * @covers Koch\Config\AbstractConfig::__isset |
||
131 | * @covers Koch\Config\AbstractConfig::__unset |
||
132 | */ |
||
133 | View Code Duplication | public function test__set() |
|
146 | |||
147 | /** |
||
148 | * @covers Koch\Config\AbstractConfig::offsetExists |
||
149 | */ |
||
150 | public function testOffsetExists() |
||
156 | |||
157 | /** |
||
158 | * @covers Koch\Config\AbstractConfig::offsetGet |
||
159 | */ |
||
160 | public function testOffsetGet() |
||
166 | |||
167 | /** |
||
168 | * @covers Koch\Config\AbstractConfig::offsetSet |
||
169 | */ |
||
170 | public function testOffsetSet() |
||
175 | |||
176 | /** |
||
177 | * @covers Koch\Config\AbstractConfig::offsetUnset |
||
178 | * |
||
179 | * @todo Implement testOffsetUnset(). |
||
180 | */ |
||
181 | public function testOffsetUnset() |
||
187 | } |
||
188 |
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.