| Conditions | 11 |
| Paths | 24 |
| Total Lines | 44 |
| Code Lines | 26 |
| Lines | 3 |
| Ratio | 6.82 % |
| Changes | 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 |
||
| 47 | public function resolve($object, array $args, $context, ResolveInfo $info) |
||
| 48 | { |
||
| 49 | $request = Controller::curr()->getRequest(); |
||
| 50 | $authenticator = Injector::inst()->get(JWTAuthenticator::class); |
||
| 51 | $member = null; |
||
| 52 | $result = new ValidationResult(); |
||
| 53 | $matches = HeaderExtractor::getAuthorizationHeader($request); |
||
| 54 | |||
| 55 | View Code Duplication | if (!empty($matches[1])) { |
|
| 56 | $member = $authenticator->authenticate(['token' => $matches[1]], $request, $result); |
||
| 57 | } |
||
| 58 | |||
| 59 | $expired = false; |
||
| 60 | // If we have a valid member, or there are no matches, there's no reason to go in here |
||
| 61 | if ($member === null && !empty($matches[1])) { |
||
| 62 | foreach ($result->getMessages() as $message) { |
||
| 63 | if (strpos($message['message'], 'Token is expired') !== false) { |
||
| 64 | // If expired is true, the rest of the token is valid, so we can refresh |
||
| 65 | $expired = true; |
||
| 66 | // We need a member, even if the result is false |
||
| 67 | $parser = new Parser(); |
||
| 68 | $parsedToken = $parser->parse((string)$matches[1]); |
||
| 69 | /** @var Member $member */ |
||
| 70 | $member = Member::get() |
||
| 71 | ->filter(['JWTUniqueID' => $parsedToken->getClaim('jti')]) |
||
| 72 | ->byID($parsedToken->getClaim('uid')); |
||
| 73 | } |
||
| 74 | } |
||
| 75 | } elseif ($member) { |
||
| 76 | $expired = true; |
||
| 77 | } |
||
| 78 | |||
| 79 | if ($expired && $member) { |
||
| 80 | $member->Token = $authenticator->generateToken($member); |
||
| 81 | } else { |
||
| 82 | // Everything is wrong, give an empty member without token |
||
| 83 | $member = Member::create(['ID' => 0, 'FirstName' => 'Anonymous']); |
||
| 84 | } |
||
| 85 | // Maybe not _everything_, we possibly have an anonymous allowed user |
||
| 86 | if ($member->ID === 0 && JWTAuthenticator::config()->get('anonymous_allowed')) { |
||
| 87 | $member->Token = $authenticator->generateToken($member); |
||
| 88 | } |
||
| 89 | |||
| 90 | return $member; |
||
| 91 | } |
||
| 93 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths