| Conditions | 13 |
| Paths | 4 |
| Total Lines | 57 |
| Code Lines | 31 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 182 |
| Changes | 6 | ||
| 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 |
||
| 38 | public function __invoke( |
||
| 39 | ServerRequestInterface $request, |
||
| 40 | ResponseInterface $response, |
||
| 41 | callable $next = null |
||
| 42 | ) |
||
| 43 | { |
||
| 44 | /** @var $response ResourceDoResponse */ |
||
| 45 | $this->checkResponseOrDie($response); |
||
| 46 | $action = $this->getAction($request); |
||
|
1 ignored issue
–
show
|
|||
| 47 | $resourceDO = $response->getContent(); |
||
|
1 ignored issue
–
show
|
|||
| 48 | $resourceNamespace = $resourceDO->getNamespace(); |
||
| 49 | $userNamespace = $this->user->getNamespace(); |
||
|
1 ignored issue
–
show
|
|||
| 50 | $AclResourceCommon = get_class($resourceDO); |
||
| 51 | $AclResourceUnique = $resourceDO instanceof ResourceInterface |
||
| 52 | ? $resourceDO->getResourceId() |
||
| 53 | : null; |
||
| 54 | |||
| 55 | if ( |
||
| 56 | // User have access to this type of resources regardless namespaces |
||
| 57 | $this->isAllowed($AclResourceCommon, $action, '') |
||
| 58 | |||
| 59 | // User have access to this unique resource regardless namespaces |
||
| 60 | || $this->isAllowed($AclResourceUnique, $action, '') |
||
| 61 | |||
| 62 | // User have access to this resource type in common namespace |
||
| 63 | || ( |
||
| 64 | !$resourceNamespace |
||
| 65 | && $this->isAllowed($AclResourceCommon, $action, ResourceDOInterface::NAMESPACES_WILDCARD) |
||
| 66 | ) |
||
| 67 | |||
| 68 | // User have access to this resource type in concrete selected namespace |
||
| 69 | || ( |
||
| 70 | $resourceNamespace |
||
| 71 | && $this->isAllowed($AclResourceCommon, $action, $resourceNamespace) |
||
| 72 | ) |
||
| 73 | || ( |
||
| 74 | // This is a user home namespace |
||
| 75 | $resourceNamespace === $userNamespace |
||
| 76 | |||
| 77 | // User have access to the current action in his own namespace |
||
| 78 | && $this->isAllowed($AclResourceCommon, $action, UserInterface::NAMESPACES_WILDCARD) |
||
| 79 | ) |
||
| 80 | || ( |
||
| 81 | // This is an another user namespace |
||
| 82 | $resourceNamespace !== $userNamespace |
||
| 83 | && 0 === strpos($resourceNamespace, UserInterface::NAMESPACES) |
||
| 84 | |||
| 85 | // User have access to the current action in his own namespace |
||
| 86 | && $this->isAllowedForGuest($AclResourceCommon, $action, UserInterface::NAMESPACES_WILDCARD) |
||
| 87 | ) |
||
| 88 | ) { |
||
| 89 | |||
| 90 | return $next($request, $response); |
||
| 91 | } |
||
| 92 | |||
| 93 | return new EmptyResponse(403); |
||
| 94 | } |
||
| 95 | |||
| 171 | } |
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.