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 |
||
10 | class Compact implements SerializerInterface |
||
11 | { |
||
12 | /** |
||
13 | * @var Encoding\EncoderInterface |
||
14 | */ |
||
15 | private $encoding; |
||
16 | |||
17 | /** |
||
18 | * @var HeaderParameter\Factory |
||
19 | */ |
||
20 | private $headerParameterFactory; |
||
21 | |||
22 | /** |
||
23 | * @var Claim\Factory |
||
24 | */ |
||
25 | private $claimFactory; |
||
26 | |||
27 | /** |
||
28 | * @param Encoding\EncoderInterface $encoding |
||
29 | * @param HeaderParameter\Factory $headerParameterFactory |
||
30 | * @param Claim\Factory $claimFactory |
||
31 | */ |
||
32 | public function __construct( |
||
41 | |||
42 | /** |
||
43 | * @param string $headersJson |
||
44 | * |
||
45 | * @return HeaderParameter\ParameterInterface[] |
||
46 | * @throws \InvalidArgumentException |
||
47 | */ |
||
48 | View Code Duplication | protected function parseHeaders($headersJson) |
|
65 | |||
66 | /** |
||
67 | * @param string $payloadJson |
||
68 | * |
||
69 | * @return Claim\ClaimInterface[] |
||
70 | * @throws \InvalidArgumentException |
||
71 | */ |
||
72 | View Code Duplication | protected function parsePayload($payloadJson) |
|
89 | |||
90 | /** |
||
91 | * @param string $jwt |
||
92 | * |
||
93 | * @return Token |
||
94 | * @throws \InvalidArgumentException |
||
95 | */ |
||
96 | public function deserialize($jwt) |
||
122 | |||
123 | /** |
||
124 | * @param Token $token |
||
125 | * @return string |
||
126 | */ |
||
127 | View Code Duplication | public function serialize(Token $token) |
|
139 | } |
||
140 |