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 CardResourceTest extends TestCase |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * @var BunqClient|ObjectProphecy |
||
| 14 | */ |
||
| 15 | private $bunqClient; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * @var CardResource |
||
| 19 | */ |
||
| 20 | private $resource; |
||
| 21 | |||
| 22 | public function setUp() |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @test |
||
| 30 | */ |
||
| 31 | public function itReturnsAListOfCards() |
||
| 61 | |||
| 62 | /** |
||
| 63 | * @test |
||
| 64 | */ |
||
| 65 | View Code Duplication | public function itReturnsASingleCard() |
|
| 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: