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 |
||
10 | final class UserResourceTest extends TestCase |
||
11 | { |
||
12 | /** |
||
13 | * @var BunqClient|ObjectProphecy |
||
14 | */ |
||
15 | private $bunqClient; |
||
16 | |||
17 | /** |
||
18 | * @var UserResource |
||
19 | */ |
||
20 | private $resource; |
||
21 | |||
22 | public function setUp() |
||
27 | |||
28 | /** |
||
29 | * @test |
||
30 | */ |
||
31 | public function itReturnsAListOfUsers() |
||
59 | |||
60 | /** |
||
61 | * @test |
||
62 | */ |
||
63 | View Code Duplication | public function itReturnsASingleUser() |
|
85 | } |
||
86 | |||
87 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: