Conditions | 9 |
Paths | 108 |
Total Lines | 55 |
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_GROUPS => $this->uriManager->getAppliedGroups($uri), |
||
82 | ]) |
||
83 | ); |
||
84 | |||
85 | $rawAppliedGroups = [] !== $this->getOption(self::OPT_APPLIED_GROUPS, $options) ? $this->getOption(self::OPT_APPLIED_GROUPS, $options) : $this->getOption(self::OPT_DEFAULT_GROUPS, $options); |
||
86 | $rawAvailableGroups = $this->getOption(self::OPT_AVAILABLE_GROUPS, $options); |
||
87 | $appliedGroups = []; |
||
88 | $availableGroups = []; |
||
89 | |||
90 | |||
91 | // Add to available if necessary |
||
92 | foreach ($rawAppliedGroups as $field) { |
||
93 | if (!array_key_exists($field, $rawAvailableGroups)) { |
||
94 | $rawAvailableGroups[] = $field; |
||
95 | } |
||
96 | } |
||
97 | |||
98 | // Create URIs |
||
99 | foreach ($rawAppliedGroups as $f => $field) { |
||
100 | $stack = $rawAppliedGroups; |
||
101 | unset($stack[$f]); |
||
102 | $stack = array_values($stack); |
||
103 | |||
104 | $uri = $this->uriManager->buildGroupUri($uri, $stack); |
||
105 | $appliedGroups[] = new Group($field, true, $uri); |
||
106 | } |
||
107 | |||
108 | |||
109 | // Cleanup |
||
110 | foreach ($rawAvailableGroups as $f => $field) { |
||
111 | if (in_array($field, $rawAppliedGroups)) { |
||
112 | unset($rawAvailableGroups[$f]); |
||
113 | } |
||
114 | } |
||
115 | $rawAvailableGroups = array_values($rawAvailableGroups); |
||
116 | |||
117 | // Generate available groups |
||
118 | foreach ($rawAvailableGroups as $field) { |
||
119 | if (true === $this->getOption(self::OPT_ENABLE_MULTIGROUP, $options)) { |
||
120 | $stack = $rawAppliedGroups; |
||
121 | $stack[] = $field; |
||
122 | } else { |
||
123 | $stack = [$field]; |
||
124 | } |
||
125 | $uri = $this->uriManager->buildGroupUri($uri, $stack); |
||
126 | $availableGroups[] = new Group($field, false, $uri); |
||
127 | } |
||
128 | |||
129 | |||
130 | return new BreakDownComponent(array_merge($appliedGroups, $availableGroups)); |
||
131 | } |
||
132 | } |
||
133 |