| Conditions | 10 |
| Paths | 30 |
| Total Lines | 31 |
| Code Lines | 21 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 26 |
| CRAP Score | 10 |
| Changes | 3 | ||
| Bugs | 1 | 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 |
||
| 21 | 16 | final public function __invoke($tokenString, $validateClaims = []) |
|
| 22 | { |
||
| 23 | 16 | $token = (new Parser())->parse((string) $tokenString); |
|
| 24 | 16 | $signer = new Sha256(); |
|
| 25 | 16 | if (!$token->verify($signer, $this->config['secret'])) { |
|
| 26 | 1 | return false; |
|
| 27 | } |
||
| 28 | 15 | if (!$this->checkRequiredClaims(array_keys($token->getClaims()))) { |
|
| 29 | 1 | return false; |
|
| 30 | 6 | }; |
|
| 31 | 14 | $data = new ValidationData(); |
|
| 32 | 14 | if (isset($this->config['issuer'])) { |
|
| 33 | 14 | $data->setIssuer($this->config['issuer']); |
|
| 34 | 14 | } |
|
| 35 | 14 | if (isset($this->config['audience'])) { |
|
| 36 | 1 | $data->setAudience($this->config['audience']); |
|
| 37 | 1 | } |
|
| 38 | 14 | if (!$token->validate($data)) { |
|
| 39 | 2 | return false; |
|
| 40 | } |
||
| 41 | 12 | $claims = $token->getClaims(); |
|
| 42 | 12 | foreach ($claims as $key => $value) { |
|
| 43 | 12 | $claims[$key] = $value->getValue(); |
|
| 44 | 12 | } |
|
| 45 | 12 | foreach ($validateClaims as $claim => $value) { |
|
| 46 | 10 | if (!isset($claims[$claim]) || $claims[$claim] !== $value) { |
|
| 47 | 3 | return false; |
|
| 48 | } |
||
| 49 | 9 | } |
|
| 50 | 9 | return new Token((string) $token, $claims); |
|
| 51 | } |
||
| 52 | } |
||
| 53 |