| Conditions | 21 |
| Paths | 21 |
| Total Lines | 36 |
| Code Lines | 23 |
| Lines | 15 |
| Ratio | 41.67 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 149 | public function validateClaims(array $claims) |
||
| 150 | { |
||
| 151 | if ($this->requiredClaims) { |
||
|
|
|||
| 152 | $missing = array_diff_key(array_flip($this->requiredClaims), $claims); |
||
| 153 | if (count($missing)) { |
||
| 154 | throw new \InvalidArgumentException("Missing claims: " . implode(', ', $missing)); |
||
| 155 | } |
||
| 156 | } |
||
| 157 | if ($this->issuer && !isset($claims['iss'])) { |
||
| 158 | throw new \InvalidArgumentException("Claim 'iss' is required"); |
||
| 159 | } |
||
| 160 | if ($this->minIssueTime && !isset($claims['iat'])) { |
||
| 161 | throw new \InvalidArgumentException("Claim 'iat' is required"); |
||
| 162 | } |
||
| 163 | if ($this->audience && !isset($claims['aud'])) { |
||
| 164 | throw new \InvalidArgumentException("Claim 'aud' is required"); |
||
| 165 | } |
||
| 166 | if (!isset($claims['prn']) || empty($claims['prn'])) { |
||
| 167 | throw new \InvalidArgumentException("Missing principle claim"); |
||
| 168 | } |
||
| 169 | View Code Duplication | if (isset($claims['exp']) && $claims['exp'] < time()) { |
|
| 170 | throw new \InvalidArgumentException("Token is expired by 'exp'"); |
||
| 171 | } |
||
| 172 | View Code Duplication | if (isset($claims['iat']) && $claims['iat'] < $this->minIssueTime) { |
|
| 173 | throw new \InvalidArgumentException("Server deemed your token too old"); |
||
| 174 | } |
||
| 175 | View Code Duplication | if (isset($claims['nbf']) && $claims['nbf'] > time()) { |
|
| 176 | throw new \InvalidArgumentException("Token not valid yet"); |
||
| 177 | } |
||
| 178 | View Code Duplication | if (isset($claims['iss']) && $claims['iss'] !== $this->issuer) { |
|
| 179 | throw new \InvalidArgumentException("Issuer mismatch"); |
||
| 180 | } |
||
| 181 | View Code Duplication | if (isset($claims['aud']) && $claims['aud'] !== $this->audience) { |
|
| 182 | throw new \InvalidArgumentException("Audience mismatch"); |
||
| 183 | } |
||
| 184 | } |
||
| 185 | |||
| 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.