Conditions | 10 |
Paths | 19 |
Total Lines | 34 |
Code Lines | 21 |
Lines | 0 |
Ratio | 0 % |
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 |
||
59 | public function onKernelRequest(GetResponseEvent $event) |
||
60 | { |
||
61 | $request = $event->getRequest(); |
||
62 | if (!$attributes = RequestAttributesExtractor::extractAttributes($request)) { |
||
63 | return; |
||
64 | } |
||
65 | |||
66 | $resourceMetadata = $this->resourceMetadataFactory->create($attributes['resource_class']); |
||
67 | if (isset($attributes['collection_operation_name'])) { |
||
68 | $isGranted = $resourceMetadata->getCollectionOperationAttribute($attributes['collection_operation_name'], 'is_granted', null, true); |
||
69 | } elseif (isset($attributes['item_operation_name'])) { |
||
70 | $isGranted = $resourceMetadata->getItemOperationAttribute($attributes['item_operation_name'], 'is_granted', null, true); |
||
71 | } else { |
||
72 | $isGranted = $resourceMetadata->getCollectionOperationAttribute($attributes['subresource_operation_name'], 'is_granted', null, true); |
||
73 | } |
||
74 | |||
75 | if (null === $isGranted) { |
||
76 | return; |
||
77 | } |
||
78 | |||
79 | if (null === $this->tokenStorage || null === $this->authenticationTrustResolver) { |
||
80 | throw new \LogicException(sprintf('The "symfony/security" library must be installed to use the "is_granted" attribute on class "%s".', $attributes['resource_class'])); |
||
81 | } |
||
82 | if (null === $this->tokenStorage->getToken()) { |
||
83 | throw new \LogicException(sprintf('The resource must be behind a firewall to use the "is_granted" attribute on class "%s".', $attributes['resource_class'])); |
||
84 | } |
||
85 | if (null === $this->expressionLanguage) { |
||
86 | throw new \LogicException(sprintf('The "symfony/expression-language" library must be installed to use the "is_granted" attribute on class "%s".', $attributes['resource_class'])); |
||
87 | } |
||
88 | |||
89 | if (!$this->expressionLanguage->evaluate($isGranted, $this->getVariables($request))) { |
||
90 | throw new AccessDeniedException(); |
||
91 | } |
||
92 | } |
||
93 | |||
119 |