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