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 |
||
| 11 | class ModelHydratorTest extends TestCase |
||
| 12 | { |
||
| 13 | private $hydrator; |
||
| 14 | private $model; |
||
| 15 | |||
| 16 | public function setUp() |
||
| 21 | |||
| 22 | public function testSuccessfulHydration() |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @expectedException \IBM\Watson\Common\Exception\HydrationException |
||
| 44 | * @expectedExceptionMessage The ModelHydrator requires a model class as the second parameter |
||
| 45 | */ |
||
| 46 | public function testHydrateFailsWithoutClass() |
||
| 52 | |||
| 53 | /** |
||
| 54 | * @expectedException \IBM\Watson\Common\Exception\HydrationException |
||
| 55 | * @expectedExceptionMessage The ModelHydrator cannot hydrate response with Content-Type: text/plain |
||
| 56 | */ |
||
| 57 | public function testHydrateFailsForNoneJsonResponses() |
||
| 63 | |||
| 64 | /** |
||
| 65 | * @expectedException \IBM\Watson\Common\Exception\HydrationException |
||
| 66 | */ |
||
| 67 | View Code Duplication | public function testHydrateFailsWhenJsonDecodeFails() |
|
| 74 | } |
||
| 75 |
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: