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 |
||
21 | class OpenWeatherMapExceptionTest extends \PHPUnit_Framework_TestCase |
||
22 | { |
||
23 | /** |
||
24 | * @var string |
||
25 | */ |
||
26 | protected $apiKey; |
||
27 | |||
28 | /** |
||
29 | * @var OpenWeatherMap |
||
30 | */ |
||
31 | protected $owm; |
||
32 | |||
33 | protected function setUp() |
||
38 | |||
39 | /** |
||
40 | * @expectedException \InvalidArgumentException |
||
41 | */ |
||
42 | public function testGetWeatherForecastException() |
||
47 | |||
48 | /** |
||
49 | * @expectedException \InvalidArgumentException |
||
50 | */ |
||
51 | public function testGetDailyWeatherForecastException() |
||
56 | |||
57 | /** |
||
58 | * @expectedException \Cmfcmf\OpenWeatherMap\Exception |
||
59 | */ |
||
60 | public function testGetWeatherHistoryException() |
||
64 | |||
65 | /** |
||
66 | * @expectedException \Cmfcmf\OpenWeatherMap\Exception |
||
67 | */ |
||
68 | public function testGetWeatherHistoryWithEndException() |
||
72 | |||
73 | /** |
||
74 | * @expectedException \InvalidArgumentException |
||
75 | */ |
||
76 | public function testGetWeatherHistoryInvalidArgumentException() |
||
80 | |||
81 | /** |
||
82 | * @expectedException \InvalidArgumentException |
||
83 | */ |
||
84 | public function testGetRawDailyForecastDataInvalidArgumentException() |
||
88 | |||
89 | /** |
||
90 | * @expectedException \InvalidArgumentException |
||
91 | */ |
||
92 | public function testGetRawWeatherHistoryException() |
||
96 | |||
97 | /** |
||
98 | * @expectedException \InvalidArgumentException |
||
99 | */ |
||
100 | public function testGetRawWeatherHistoryWithEndDateException() |
||
104 | |||
105 | /** |
||
106 | * @expectedException \InvalidArgumentException |
||
107 | * @dataProvider uvIndexExceptionDataProvider |
||
108 | */ |
||
109 | public function testGetRawUVIndexWithQueryErrorException($mode, $lat, $lon, $cnt, $start, $end) |
||
113 | |||
114 | /** |
||
115 | * @expectedException \InvalidArgumentException |
||
116 | */ |
||
117 | public function testBuildQueryUrlParameterException() |
||
121 | |||
122 | /** |
||
123 | * @expectedException \Cmfcmf\OpenWeatherMap\Exception |
||
124 | */ |
||
125 | View Code Duplication | public function testParseXMLException() |
|
133 | |||
134 | /** |
||
135 | * @expectedException \Cmfcmf\OpenWeatherMap\Exception |
||
136 | */ |
||
137 | public function testParseXMLWithIsJsonException() |
||
146 | |||
147 | /** |
||
148 | * @expectedException \Cmfcmf\OpenWeatherMap\Exception |
||
149 | */ |
||
150 | View Code Duplication | public function testParseJsonException() |
|
158 | |||
159 | /** |
||
160 | * @expectedException \Cmfcmf\OpenWeatherMap\Exception |
||
161 | */ |
||
162 | public function uvIndexExceptionDataProvider() |
||
175 | } |
||
176 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: