| Conditions | 12 |
| Paths | 48 |
| Total Lines | 38 |
| 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 |
||
| 77 | public function createComponent(UriInterface $uri, array $options = []): ComponentInterface |
||
| 78 | { |
||
| 79 | $options = $this->resolveOptions( |
||
| 80 | $this->getMergedOptions($options, [ |
||
| 81 | self::OPT_APPLIED_SORTS => $this->uriManager->getAppliedSorts($uri), |
||
| 82 | ]) |
||
| 83 | ); |
||
| 84 | |||
| 85 | $appliedSorts = [] !== $this->getOption(self::OPT_APPLIED_SORTS, $options) ? $this->getOption(self::OPT_APPLIED_SORTS, $options) : $this->getOption(self::OPT_DEFAULT_SORTS, $options); |
||
| 86 | $availableSorts = $this->getOption(self::OPT_AVAILABLE_SORTS, $options); |
||
| 87 | |||
| 88 | $sorts = []; |
||
| 89 | |||
| 90 | foreach ($availableSorts as $field => $directions) { |
||
| 91 | foreach ($directions as $direction) { |
||
| 92 | if (isset($appliedSorts[$field]) && $direction === $appliedSorts[$field]) { |
||
| 93 | $stack = true === $this->getOption(self::OPT_ENABLE_MULTISORT, $options) ? array_replace($appliedSorts, [$field => $direction]) : [$field => $direction]; |
||
| 94 | unset($stack[$field]); |
||
| 95 | $unsetUri = $this->uriManager->buildSortUri($uri, $stack); |
||
| 96 | $sorts[] = new Sort($field, $direction, true, $unsetUri); |
||
| 97 | continue; |
||
| 98 | } |
||
| 99 | $stack = true === $this->getOption(self::OPT_ENABLE_MULTISORT) ? array_replace($appliedSorts, [$field => $direction]) : [$field => $direction]; |
||
| 100 | $sorts[] = new Sort($field, $direction, false, $this->uriManager->buildSortUri($uri, $stack)); |
||
| 101 | } |
||
| 102 | } |
||
| 103 | |||
| 104 | foreach ($appliedSorts as $field => $direction) { |
||
| 105 | if (!array_key_exists($field, $availableSorts) || !in_array($direction, $availableSorts[$field])) { |
||
| 106 | $stack = true === $this->getOption(self::OPT_ENABLE_MULTISORT, $options) ? array_replace($appliedSorts, [$field => $direction]) : [$field => $direction]; |
||
| 107 | unset($stack[$field]); |
||
| 108 | $unsetUri = $this->uriManager->buildSortUri($uri, $stack); |
||
| 109 | $sorts[] = new Sort($field, $direction, true, $unsetUri); |
||
| 110 | } |
||
| 111 | } |
||
| 112 | |||
| 113 | return new SortComponent($sorts); |
||
| 114 | } |
||
| 115 | } |
||
| 116 |