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 | View Code Duplication | class IssuerVerifierTest 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 | public function setUp() |
||
25 | |||
26 | /** |
||
27 | * @expectedException \InvalidArgumentException |
||
28 | * @expectedExceptionMessage Cannot verify invalid issuer value. |
||
29 | */ |
||
30 | public function testInvalidIssuer() |
||
34 | |||
35 | public function testNoIssuer() |
||
49 | |||
50 | /** |
||
51 | * @expectedException \Emarref\Jwt\Exception\InvalidIssuerException |
||
52 | * @expectedExceptionMessage Issuer is invalid. |
||
53 | */ |
||
54 | public function testIssuerInPayloadOnly() |
||
75 | |||
76 | /** |
||
77 | * @expectedException \Emarref\Jwt\Exception\InvalidIssuerException |
||
78 | * @expectedExceptionMessage Issuer is invalid. |
||
79 | */ |
||
80 | public function testIssuerInContextOnly() |
||
94 | |||
95 | /** |
||
96 | * @expectedException \Emarref\Jwt\Exception\InvalidIssuerException |
||
97 | * @expectedExceptionMessage Issuer is invalid. |
||
98 | */ |
||
99 | public function testIssuerMismatch() |
||
120 | |||
121 | public function testSuccess() |
||
142 | } |
||
143 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.