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 OpenWeatherMapExceptionTest extends \PHPUnit_Framework_TestCase |
||
20 | { |
||
21 | /** |
||
22 | * @var apiKey |
||
23 | * @var weather |
||
24 | */ |
||
25 | protected $apiKey; |
||
26 | protected $weather; |
||
27 | |||
28 | View Code Duplication | protected function setUp() |
|
35 | |||
36 | /** |
||
37 | * @expectedException Exception |
||
38 | */ |
||
39 | View Code Duplication | public function testCacheException() |
|
47 | |||
48 | /** |
||
49 | * @expectedException Exception |
||
50 | */ |
||
51 | View Code Duplication | public function testSecondNotNumbericException() |
|
59 | |||
60 | /** |
||
61 | * @expectedException InvalidArgumentException |
||
62 | */ |
||
63 | View Code Duplication | public function testGetWeatherForecastException() |
|
74 | |||
75 | /** |
||
76 | * @expectedException InvalidArgumentException |
||
77 | */ |
||
78 | View Code Duplication | public function testGetDailyWeatherForecastException() |
|
89 | |||
90 | /** |
||
91 | * @expectedException \Cmfcmf\OpenWeatherMap\Exception |
||
92 | */ |
||
93 | public function testGetWeatherHistoryException() |
||
103 | |||
104 | /** |
||
105 | * @expectedException \Cmfcmf\OpenWeatherMap\Exception |
||
106 | */ |
||
107 | public function testGetWeatherHistoryWithEndException() |
||
117 | |||
118 | /** |
||
119 | * @expectedException InvalidArgumentException |
||
120 | */ |
||
121 | View Code Duplication | public function testGetWeatherHistoryInvalidArgumentException() |
|
131 | |||
132 | /** |
||
133 | * @expectedException InvalidArgumentException |
||
134 | */ |
||
135 | View Code Duplication | public function testGetRawDailyForecastDataInvalidArgumentException() |
|
145 | |||
146 | /** |
||
147 | * @expectedException InvalidArgumentException |
||
148 | */ |
||
149 | View Code Duplication | public function testGetRawWeatherHistoryException() |
|
159 | |||
160 | /** |
||
161 | * @expectedException InvalidArgumentException |
||
162 | */ |
||
163 | View Code Duplication | public function testGetRawWeatherHistoryWithEndDateException() |
|
173 | |||
174 | /** |
||
175 | * @expectedException InvalidArgumentException |
||
176 | */ |
||
177 | View Code Duplication | public function testBuildQueryUrlParameterException() |
|
187 | |||
188 | /** |
||
189 | * @expectedException Exception |
||
190 | */ |
||
191 | View Code Duplication | public function testParseXMLException() |
|
206 | |||
207 | /** |
||
208 | * @expectedException Exception |
||
209 | */ |
||
210 | public function testParseXMLWithIsJsonException() |
||
226 | |||
227 | /** |
||
228 | * @expectedException \Cmfcmf\OpenWeatherMap\Exception |
||
229 | */ |
||
230 | View Code Duplication | public function testParseJsonException() |
|
245 | } |
||
246 |
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.