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 |
||
7 | class NotBeforeVerifierTest extends \PHPUnit_Framework_TestCase |
||
8 | { |
||
9 | /** |
||
10 | * @var \PHPUnit_Framework_MockObject_MockObject|\Emarref\Jwt\Token\Payload |
||
11 | */ |
||
12 | private $payload; |
||
13 | |||
14 | /** |
||
15 | * @var \PHPUnit_Framework_MockObject_MockObject|\Emarref\Jwt\Token |
||
16 | */ |
||
17 | private $token; |
||
18 | |||
19 | /** |
||
20 | * @var NotBeforeVerifier |
||
21 | */ |
||
22 | private $verifier; |
||
23 | |||
24 | View Code Duplication | public function setUp() |
|
36 | |||
37 | View Code Duplication | public function testMissingNotBefore() |
|
46 | |||
47 | /** |
||
48 | * @expectedException \Emarref\Jwt\Exception\TooEarlyException |
||
49 | * @expectedExceptionMessageRegExp /Token must not be processed before "[\w,:+\d ]+"/ |
||
50 | */ |
||
51 | View Code Duplication | public function testNotBefore() |
|
68 | |||
69 | /** |
||
70 | * @expectedException \InvalidArgumentException |
||
71 | * @expectedExceptionMessage Invalid not before timestamp "foobar" |
||
72 | */ |
||
73 | View Code Duplication | public function testUnexpectedValue() |
|
88 | |||
89 | View Code Duplication | public function testValid() |
|
106 | } |
||
107 |
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: