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