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 |
||
13 | class ModelHydratorTest extends TestCase |
||
14 | { |
||
15 | private $hydrator; |
||
16 | private $model; |
||
17 | |||
18 | public function setUp() |
||
23 | |||
24 | public function testSuccessfulHydration() |
||
34 | |||
35 | /** |
||
36 | * @expectedException \IBM\Watson\Common\Exception\HydrationException |
||
37 | * @expectedExceptionMessage The ModelHydrator requires a model class as the second parameter |
||
38 | */ |
||
39 | public function testHydrateFailsWithoutClass() |
||
45 | |||
46 | /** |
||
47 | * @expectedException \IBM\Watson\Common\Exception\HydrationException |
||
48 | * @expectedExceptionMessage The ModelHydrator cannot hydrate response with Content-Type: text/plain |
||
49 | */ |
||
50 | public function testHydrateFailsForNoneJsonResponses() |
||
56 | |||
57 | /** |
||
58 | * @expectedException \IBM\Watson\Common\Exception\HydrationException |
||
59 | * @expectedExceptionMessage Error (3) when trying to json_decode response |
||
60 | */ |
||
61 | View Code Duplication | public function testHydrateFailsWhenJsonDecodeFails() |
|
68 | } |
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: