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 |
||
16 | abstract class SignatureAlgorithm implements |
||
17 | AlgorithmParameterValue, |
||
|
|||
18 | HeaderParameters |
||
19 | { |
||
20 | /** |
||
21 | * ID of the key used by the algorithm. |
||
22 | * |
||
23 | * If set, KeyID parameter shall be automatically inserted into JWS's |
||
24 | * header. |
||
25 | * |
||
26 | * @var string|null $_keyID |
||
27 | */ |
||
28 | protected $_keyID; |
||
29 | |||
30 | /** |
||
31 | * Compute signature. |
||
32 | * |
||
33 | * @param string $data Data for which the signature is computed |
||
34 | * @return string |
||
35 | */ |
||
36 | abstract public function computeSignature($data); |
||
37 | |||
38 | /** |
||
39 | * Validate signature. |
||
40 | * |
||
41 | * @param string $data Data to validate |
||
42 | * @param string $signature Signature to compare |
||
43 | * @return bool |
||
44 | */ |
||
45 | abstract public function validateSignature($data, $signature); |
||
46 | |||
47 | /** |
||
48 | * Initialize signature algorithm from a JWK and a header. |
||
49 | * |
||
50 | * @param JWK $jwk JSON Web Key |
||
51 | * @param Header $header Header |
||
52 | * @return SignatureAlgorithm |
||
53 | */ |
||
54 | 5 | public static function fromJWK(JWK $jwk, Header $header) { |
|
58 | |||
59 | /** |
||
60 | * Get self with key ID. |
||
61 | * |
||
62 | * @param string|null $id Key ID or null to remove |
||
63 | * @return self |
||
64 | */ |
||
65 | 2 | public function withKeyID($id) { |
|
70 | |||
71 | /** |
||
72 | * |
||
73 | * @see \JWX\JWT\Header\HeaderParameters::headerParameters() |
||
74 | * @return JWTParameter[] |
||
75 | */ |
||
76 | 18 | View Code Duplication | public function headerParameters() { |
83 | } |
||
84 |