Conditions | 17 |
Paths | 277 |
Total Lines | 59 |
Code Lines | 34 |
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 |
||
62 | public function onKernelRequest(RequestEvent $event): void |
||
63 | { |
||
64 | $request = $event->getRequest(); |
||
65 | if ( |
||
66 | !($attributes = RequestAttributesExtractor::extractAttributes($request)) |
||
67 | || !$attributes['receive'] |
||
68 | || $request->isMethod('POST') && isset($attributes['collection_operation_name']) |
||
69 | || $this->isOperationAttributeDisabled($attributes, self::OPERATION_ATTRIBUTE_KEY) |
||
70 | ) { |
||
71 | return; |
||
72 | } |
||
73 | |||
74 | if (null === $filters = $request->attributes->get('_api_filters')) { |
||
75 | $queryString = RequestParser::getQueryString($request); |
||
76 | $filters = $queryString ? RequestParser::parseRequestParams($queryString) : null; |
||
77 | } |
||
78 | |||
79 | $context = null === $filters ? [] : ['filters' => $filters]; |
||
80 | if ($this->serializerContextBuilder) { |
||
81 | // Builtin data providers are able to use the serialization context to automatically add join clauses |
||
82 | $context += $normalizationContext = $this->serializerContextBuilder->createFromRequest($request, true, $attributes); |
||
83 | $request->attributes->set('_api_normalization_context', $normalizationContext); |
||
84 | } |
||
85 | |||
86 | if (isset($attributes['collection_operation_name'])) { |
||
87 | $request->attributes->set('data', $this->getCollectionData($attributes, $context)); |
||
88 | |||
89 | return; |
||
90 | } |
||
91 | |||
92 | $data = []; |
||
93 | |||
94 | if ($this->identifierConverter) { |
||
95 | $context[IdentifierConverterInterface::HAS_IDENTIFIER_CONVERTER] = true; |
||
96 | } |
||
97 | |||
98 | try { |
||
99 | $identifiers = $this->extractIdentifiers($request->attributes->all(), $attributes); |
||
100 | |||
101 | if (isset($attributes['item_operation_name'])) { |
||
102 | $data = $this->getItemData($identifiers, $attributes, $context); |
||
103 | } elseif (isset($attributes['subresource_operation_name'])) { |
||
104 | // Legacy |
||
105 | if (null === $this->subresourceDataProvider) { |
||
106 | throw new RuntimeException('No subresource data provider.'); |
||
107 | } |
||
108 | |||
109 | $data = $this->getSubresourceData($identifiers, $attributes, $context); |
||
110 | } |
||
111 | } catch (InvalidIdentifierException $e) { |
||
112 | throw new NotFoundHttpException('Invalid identifier value or configuration.', $e); |
||
113 | } |
||
114 | |||
115 | if (null === $data) { |
||
116 | throw new NotFoundHttpException('Not Found'); |
||
117 | } |
||
118 | |||
119 | $request->attributes->set('data', $data); |
||
120 | $request->attributes->set('previous_data', $this->clone($data)); |
||
121 | } |
||
123 |