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 |
||
| 15 | class DoctrineORMTokenRepositoryTest extends TestCase |
||
| 16 | { |
||
| 17 | /** |
||
| 18 | * @var EntityManager|ObjectProphecy |
||
| 19 | */ |
||
| 20 | private $manager; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @var EntityRepository|ObjectProphecy |
||
| 24 | */ |
||
| 25 | private $repository; |
||
| 26 | |||
| 27 | protected function setUp() |
||
| 32 | |||
| 33 | protected function tearDown() |
||
| 40 | |||
| 41 | protected function repository() |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @test |
||
| 48 | * @expectedException \Yokai\SecurityTokenBundle\Exception\TokenNotFoundException |
||
| 49 | */ |
||
| 50 | public function it_throw_exception_if_token_not_found() |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @test |
||
| 61 | * @expectedException \Yokai\SecurityTokenBundle\Exception\TokenExpiredException |
||
| 62 | */ |
||
| 63 | public function it_throw_exception_if_token_expired() |
||
| 73 | |||
| 74 | /** |
||
| 75 | * @test |
||
| 76 | * @expectedException \Yokai\SecurityTokenBundle\Exception\TokenUsedException |
||
| 77 | */ |
||
| 78 | public function it_throw_exception_if_token_used() |
||
| 90 | |||
| 91 | /** |
||
| 92 | * @test |
||
| 93 | */ |
||
| 94 | public function it_get_valid_token() |
||
| 106 | |||
| 107 | /** |
||
| 108 | * @test |
||
| 109 | */ |
||
| 110 | View Code Duplication | public function it_create_token() |
|
| 121 | |||
| 122 | /** |
||
| 123 | * @test |
||
| 124 | */ |
||
| 125 | View Code Duplication | public function it_update_token() |
|
| 136 | } |
||
| 137 |
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: