Conditions | 10 |
Paths | 18 |
Total Lines | 42 |
Code Lines | 24 |
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 |
||
71 | public function normalize($object, $format = null, array $context = []) |
||
72 | { |
||
73 | $data = $this->collectionNormalizer->normalize($object, $format, $context); |
||
74 | if (!\is_array($data)) { |
||
75 | throw new UnexpectedValueException('Expected data to be an array'); |
||
76 | } |
||
77 | |||
78 | if (!isset($context['resource_class']) || isset($context['api_sub_level'])) { |
||
79 | return $data; |
||
80 | } |
||
81 | |||
82 | $resourceClass = $this->resourceClassResolver->getResourceClass($object, $context['resource_class']); |
||
83 | $resourceMetadata = $this->resourceMetadataFactory->create($resourceClass); |
||
84 | |||
85 | $operationName = $context['collection_operation_name'] ?? null; |
||
86 | if (null === $operationName) { |
||
87 | $resourceFilters = $resourceMetadata->getAttribute('filters', []); |
||
88 | } else { |
||
89 | $resourceFilters = $resourceMetadata->getCollectionOperationAttribute($operationName, 'filters', [], true); |
||
90 | } |
||
91 | |||
92 | if (!$resourceFilters) { |
||
93 | return $data; |
||
94 | } |
||
95 | |||
96 | $requestParts = parse_url($context['request_uri'] ?? ''); |
||
97 | if (!\is_array($requestParts)) { |
||
|
|||
98 | return $data; |
||
99 | } |
||
100 | |||
101 | $currentFilters = []; |
||
102 | foreach ($resourceFilters as $filterId) { |
||
103 | if ($filter = $this->getFilter($filterId)) { |
||
104 | $currentFilters[] = $filter; |
||
105 | } |
||
106 | } |
||
107 | |||
108 | if ($currentFilters) { |
||
109 | $data['hydra:search'] = $this->getSearch($resourceClass, $requestParts, $currentFilters); |
||
110 | } |
||
111 | |||
112 | return $data; |
||
113 | } |
||
154 |