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 |
||
6 | class JwtWrapperHashTest extends TestCase |
||
7 | { |
||
8 | |||
9 | /** |
||
10 | * @var JwtWrapper |
||
11 | */ |
||
12 | protected $object; |
||
13 | |||
14 | protected $dataToToken = ["name" => "John", "id"=>"1"]; |
||
15 | protected $server = "example.com"; |
||
16 | |||
17 | /** |
||
18 | * @var \ByJG\Util\JwtKeyInterface |
||
19 | */ |
||
20 | protected $jwtKey; |
||
21 | |||
22 | protected function setUp() |
||
29 | |||
30 | protected function tearDown() |
||
35 | |||
36 | |||
37 | View Code Duplication | public function testSuccessfulFlow1() |
|
68 | |||
69 | View Code Duplication | public function testSuccessfulFlow2() |
|
102 | |||
103 | /** |
||
104 | * @throws \ByJG\Util\JwtWrapperException |
||
105 | * @expectedException \ByJG\Util\JwtWrapperException |
||
106 | */ |
||
107 | View Code Duplication | public function testTokenWrongServerSameSecret() |
|
116 | |||
117 | /** |
||
118 | * @throws \ByJG\Util\JwtWrapperException |
||
119 | * @expectedException \Firebase\JWT\SignatureInvalidException |
||
120 | */ |
||
121 | View Code Duplication | public function testTokenWrongSecret() |
|
130 | |||
131 | /** |
||
132 | * @throws \ByJG\Util\JwtWrapperException |
||
133 | * @expectedException \Firebase\JWT\ExpiredException |
||
134 | */ |
||
135 | View Code Duplication | public function testExpiredToken() |
|
144 | |||
145 | /** |
||
146 | * @throws \ByJG\Util\JwtWrapperException |
||
147 | * @expectedException \Firebase\JWT\BeforeValidException |
||
148 | */ |
||
149 | View Code Duplication | public function testNotBeforeToken() |
|
156 | |||
157 | /** |
||
158 | * @throws \ByJG\Util\JwtWrapperException |
||
159 | * @expectedException \ByJG\Util\JwtWrapperException |
||
160 | */ |
||
161 | public function testGetEmptyAuthorizationBearer() |
||
165 | |||
166 | /** |
||
167 | * @throws \ByJG\Util\JwtWrapperException |
||
168 | * @expectedException UnexpectedValueException |
||
169 | */ |
||
170 | public function testGetInvalidTokenSequence() |
||
174 | |||
175 | /** |
||
176 | * @throws \ByJG\Util\JwtWrapperException |
||
177 | * @expectedException DomainException |
||
178 | */ |
||
179 | public function testGetInvalidToken() |
||
183 | } |
||
184 |
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.