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 |
||
| 25 | class OpenWeatherMapExceptionTest extends \PHPUnit_Framework_TestCase |
||
| 26 | { |
||
| 27 | /** |
||
| 28 | * @var string |
||
| 29 | */ |
||
| 30 | protected $apiKey; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @var OpenWeatherMap |
||
| 34 | */ |
||
| 35 | protected $owm; |
||
| 36 | |||
| 37 | protected function setUp() |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @expectedException \InvalidArgumentException |
||
| 45 | */ |
||
| 46 | public function testGetWeatherForecastException() |
||
| 51 | |||
| 52 | /** |
||
| 53 | * @expectedException \InvalidArgumentException |
||
| 54 | */ |
||
| 55 | public function testGetDailyWeatherForecastException() |
||
| 60 | |||
| 61 | /** |
||
| 62 | * @expectedException \InvalidArgumentException |
||
| 63 | */ |
||
| 64 | public function testGetRawDailyForecastDataInvalidArgumentException() |
||
| 68 | |||
| 69 | /** |
||
| 70 | * @expectedException \InvalidArgumentException |
||
| 71 | * @dataProvider uvIndexExceptionDataProvider |
||
| 72 | */ |
||
| 73 | public function testGetRawUVIndexWithQueryErrorException($mode, $lat, $lon, $cnt, $start, $end) |
||
| 77 | |||
| 78 | /** |
||
| 79 | * @expectedException \InvalidArgumentException |
||
| 80 | */ |
||
| 81 | public function testBuildQueryUrlParameterException() |
||
| 85 | |||
| 86 | /** |
||
| 87 | * @expectedException \Cmfcmf\OpenWeatherMap\Exception |
||
| 88 | */ |
||
| 89 | public function testParseXMLException() |
||
| 97 | |||
| 98 | /** |
||
| 99 | * @expectedException \Cmfcmf\OpenWeatherMap\Exception |
||
| 100 | */ |
||
| 101 | public function testParseXMLWithIsJsonException() |
||
| 110 | |||
| 111 | /** |
||
| 112 | * @expectedException \Cmfcmf\OpenWeatherMap\Exception |
||
| 113 | */ |
||
| 114 | public function testParseJsonException() |
||
| 122 | |||
| 123 | /** |
||
| 124 | * @expectedException \Cmfcmf\OpenWeatherMap\Exception |
||
| 125 | */ |
||
| 126 | public function uvIndexExceptionDataProvider() |
||
| 139 | } |
||
| 140 |
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: