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 |
||
19 | class ClientTest extends \PHPUnit_Framework_TestCase |
||
20 | { |
||
21 | /** |
||
22 | * client |
||
23 | * @var \Unikorp\KongAdminApi\Client |
||
24 | */ |
||
25 | private $client = null; |
||
26 | |||
27 | /** |
||
28 | * set up |
||
29 | * |
||
30 | * @return void |
||
31 | * |
||
32 | * @coversNothing |
||
33 | */ |
||
34 | public function setUp() |
||
39 | |||
40 | /** |
||
41 | * tear down |
||
42 | * |
||
43 | * @return void |
||
44 | * |
||
45 | * @coversNothing |
||
46 | */ |
||
47 | public function tearDown() |
||
52 | |||
53 | /** |
||
54 | * test constructor set http client |
||
55 | * |
||
56 | * @return void |
||
57 | * |
||
58 | * @covers \Unikorp\KongAdminApi\Client::__construct |
||
59 | */ |
||
60 | View Code Duplication | public function testConstructorSetHttpClient() |
|
72 | |||
73 | /** |
||
74 | * test constructor set message factory |
||
75 | * |
||
76 | * @return void |
||
77 | * |
||
78 | * @covers \Unikorp\KongAdminApi\Client::__construct |
||
79 | */ |
||
80 | View Code Duplication | public function testConstructorSetMessageFactory() |
|
92 | |||
93 | /** |
||
94 | * test constructor add host plugin |
||
95 | * |
||
96 | * @return void |
||
97 | * |
||
98 | * @covers \Unikorp\KongAdminApi\Client::__construct |
||
99 | */ |
||
100 | public function testConstructorAddHostPlugin() |
||
126 | |||
127 | /** |
||
128 | * test api when valid |
||
129 | * |
||
130 | * @param string $name |
||
131 | * @param string $class |
||
132 | * |
||
133 | * @return void |
||
134 | * |
||
135 | * @covers \Unikorp\KongAdminApi\Client::api |
||
136 | * @dataProvider validApiNameProvider |
||
137 | */ |
||
138 | public function testApiWhenValid($name, $class) |
||
143 | |||
144 | /** |
||
145 | * test api when invalid |
||
146 | * |
||
147 | * @return void |
||
148 | * |
||
149 | * @covers \Unikorp\KongAdminApi\Client::api |
||
150 | * @expectedException \InvalidArgumentException |
||
151 | * @expectedExceptionMessage Undefined api instance called: something |
||
152 | */ |
||
153 | public function testApiWhenInvalid() |
||
157 | |||
158 | /** |
||
159 | * test add plugin |
||
160 | * |
||
161 | * @return void |
||
162 | * |
||
163 | * @covers \Unikorp\KongAdminApi\Client::addPlugin |
||
164 | */ |
||
165 | public function testAddPlugin() |
||
181 | |||
182 | /** |
||
183 | * test get http client |
||
184 | * |
||
185 | * @return void |
||
186 | * |
||
187 | * @covers \Unikorp\KongAdminApi\Client::getHttpClient |
||
188 | */ |
||
189 | public function testGetHttpClient() |
||
193 | |||
194 | /** |
||
195 | * valid api name provider |
||
196 | * |
||
197 | * @return array |
||
198 | */ |
||
199 | public function validApiNameProvider() |
||
207 | } |
||
208 |
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.