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 |
||
18 | class JwtKey |
||
19 | { |
||
20 | const TYPE_HMAC = 'HS256'; |
||
21 | const TYPE_RSA = 'RS256'; |
||
22 | |||
23 | /** |
||
24 | * @var string |
||
25 | */ |
||
26 | private $id; |
||
27 | |||
28 | /** |
||
29 | * @var string |
||
30 | */ |
||
31 | private $issuer; |
||
32 | |||
33 | /** |
||
34 | * @var string |
||
35 | */ |
||
36 | private $type = self::TYPE_HMAC; |
||
37 | |||
38 | /** |
||
39 | * @var string |
||
40 | */ |
||
41 | private $audience; |
||
42 | |||
43 | /** |
||
44 | * @var int |
||
45 | */ |
||
46 | private $minIssueTime; |
||
47 | |||
48 | /** |
||
49 | * @var array |
||
50 | */ |
||
51 | private $requiredClaims = []; |
||
52 | |||
53 | /** |
||
54 | * @var int |
||
55 | */ |
||
56 | private $issuerTimeLeeway; |
||
57 | |||
58 | /** |
||
59 | * @var string |
||
60 | */ |
||
61 | private $secret; |
||
62 | |||
63 | /** |
||
64 | * @var SecretLoader |
||
65 | */ |
||
66 | private $secretLoader; |
||
67 | |||
68 | /** |
||
69 | * @param array $options |
||
70 | */ |
||
71 | public function __construct(array $options) |
||
100 | |||
101 | /** |
||
102 | * @return string |
||
103 | */ |
||
104 | public function getId() |
||
108 | |||
109 | /** |
||
110 | * @param JwtToken $token |
||
111 | * |
||
112 | * @throws \InvalidArgumentException |
||
113 | */ |
||
114 | public function validateToken(JwtToken $token) |
||
125 | |||
126 | /** |
||
127 | * @param array $header |
||
128 | * |
||
129 | * @throws \InvalidArgumentException |
||
130 | */ |
||
131 | public function validateHeader(array $header) |
||
143 | |||
144 | /** |
||
145 | * @param array $claims |
||
146 | * |
||
147 | * @throws \InvalidArgumentException |
||
148 | */ |
||
149 | public function validateClaims(array $claims) |
||
185 | |||
186 | |||
187 | /** |
||
188 | * @return SignatureValidator |
||
189 | */ |
||
190 | public function getSignatureValidator() |
||
198 | |||
199 | /** |
||
200 | * Prevent accidental persistence of secret |
||
201 | */ |
||
202 | final public function __sleep() |
||
206 | } |
||
207 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.