| Conditions | 12 |
| Paths | 97 |
| Total Lines | 43 |
| Code Lines | 29 |
| 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 |
||
| 45 | public function createFromRequest(Request $request, bool $normalization, array $extractedAttributes = null) : array |
||
| 46 | { |
||
| 47 | $context = $this->decorated->createFromRequest($request, $normalization, $extractedAttributes); |
||
| 48 | if (isset($context['groups']) && in_array('none', $context['groups'])) { |
||
| 49 | return $context; |
||
| 50 | } |
||
| 51 | $subject = $request->attributes->get('_api_resource_class'); |
||
| 52 | $operation = $context['item_operation_name'] ?? null; |
||
| 53 | $groups = []; |
||
| 54 | if ( |
||
| 55 | $this->matchClass($subject, AbstractComponent::class) || |
||
| 56 | $this->matchClass($subject, AbstractNavigation::class) || |
||
| 57 | $this->matchClass($subject, ComponentLocation::class) |
||
| 58 | ) { |
||
| 59 | $groups[] = $this->getGroups('component', $normalization, $operation); |
||
| 60 | } |
||
| 61 | if ( |
||
| 62 | $this->matchClass($subject, AbstractNavigationItem::class) |
||
| 63 | ) { |
||
| 64 | $groups[] = $this->getGroups('component_item', $normalization, $operation); |
||
| 65 | } |
||
| 66 | if ( |
||
| 67 | $this->matchClass($subject, AbstractContent::class) |
||
| 68 | ) { |
||
| 69 | $groups[] = $this->getGroups('content', $normalization, $operation); |
||
| 70 | } |
||
| 71 | if ( |
||
| 72 | $this->matchClass($subject, Route::class) |
||
| 73 | ) { |
||
| 74 | $groups[] = $this->getGroups('route', $normalization, $operation); |
||
| 75 | } |
||
| 76 | if ($this->matchClass($subject, Layout::class)) { |
||
| 77 | $groups[] = $this->getGroups('layout', $normalization, $operation); |
||
| 78 | } |
||
| 79 | if (\count($groups)) { |
||
| 80 | if (!isset($context['groups'])) { |
||
| 81 | $context['groups'] = ['default']; |
||
| 82 | } else { |
||
| 83 | $context['groups'][] = ['default']; |
||
| 84 | } |
||
| 85 | $context['groups'] = array_merge($context['groups'], ...$groups); |
||
|
|
|||
| 86 | } |
||
| 87 | return $context; |
||
| 88 | } |
||
| 90 |