Conditions | 11 |
Paths | 7 |
Total Lines | 34 |
Code Lines | 20 |
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 |
||
40 | public function onKernelRequest(GetResponseEvent $event) |
||
41 | { |
||
42 | $request = $event->getRequest(); |
||
43 | if ( |
||
44 | !$request->isMethodSafe(false) |
||
45 | || !($attributes = RequestAttributesExtractor::extractAttributes($request)) |
||
46 | || !isset($attributes['collection_operation_name']) |
||
47 | || 'get' !== ($operationName = $attributes['collection_operation_name']) |
||
48 | ) { |
||
49 | return; |
||
50 | } |
||
51 | |||
52 | $resourceMetadata = $this->resourceMetadataFactory->create($attributes['resource_class']); |
||
53 | $resourceFilters = $resourceMetadata->getCollectionOperationAttribute($operationName, 'filters', [], true); |
||
54 | |||
55 | $errorList = []; |
||
56 | foreach ($resourceFilters as $filterId) { |
||
57 | if (!$filter = $this->getFilter($filterId)) { |
||
58 | continue; |
||
59 | } |
||
60 | |||
61 | foreach ($filter->getDescription($attributes['resource_class']) as $name => $data) { |
||
62 | if (!($data['required'] ?? false)) { // property is not required |
||
63 | continue; |
||
64 | } |
||
65 | |||
66 | if (!$this->isRequiredFilterValid($name, $request)) { |
||
67 | $errorList[] = sprintf('Query parameter "%s" is required', $name); |
||
68 | } |
||
69 | } |
||
70 | } |
||
71 | |||
72 | if ($errorList) { |
||
73 | throw new FilterValidationException($errorList); |
||
74 | } |
||
104 |