We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
Conditions | 17 |
Paths | 2 |
Total Lines | 112 |
Code Lines | 80 |
Lines | 0 |
Ratio | 0 % |
Tests | 82 |
CRAP Score | 17.0037 |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
116 | 15 | protected function outputFieldsSelection($name, $withAccess = false) |
|
117 | { |
||
118 | 15 | $builder = new TreeBuilder(); |
|
119 | 15 | $node = $builder->root($name); |
|
120 | $node |
||
121 | 15 | ->isRequired() |
|
122 | 15 | ->requiresAtLeastOneElement(); |
|
123 | |||
124 | /* @var ArrayNodeDefinition $prototype */ |
||
125 | 15 | $prototype = $node->useAttributeAsKey('name', false)->prototype('array'); |
|
126 | |||
127 | $prototype |
||
128 | // build args if argsBuilder exists |
||
129 | 15 | ->beforeNormalization() |
|
130 | ->ifTrue(function ($field) { |
||
131 | 9 | return isset($field['argsBuilder']); |
|
132 | 15 | }) |
|
133 | ->then(function ($field) { |
||
134 | 4 | $argsBuilderName = null; |
|
135 | |||
136 | 4 | if (is_string($field['argsBuilder'])) { |
|
137 | 4 | $argsBuilderName = $field['argsBuilder']; |
|
138 | 4 | } elseif (isset($field['argsBuilder']['builder']) && is_string($field['argsBuilder']['builder'])) { |
|
139 | 1 | $argsBuilderName = $field['argsBuilder']['builder']; |
|
140 | 1 | } |
|
141 | |||
142 | 4 | if ($argsBuilderName) { |
|
143 | 4 | if (!($argsBuilder = $this->getArgsBuilder($argsBuilderName))) { |
|
144 | throw new InvalidConfigurationException(sprintf('Args builder "%s" not found.', $argsBuilder)); |
||
145 | } |
||
146 | |||
147 | 4 | $args = $argsBuilder->toMappingDefinition([]); |
|
148 | |||
149 | 4 | $field['args'] = isset($field['args']) && is_array($field['args']) ? array_merge($args, $field['args']) : $args; |
|
150 | 4 | } |
|
151 | |||
152 | 4 | unset($field['argsBuilder']); |
|
153 | |||
154 | 4 | return $field; |
|
155 | 15 | }) |
|
156 | 15 | ->end() |
|
157 | // build field if builder exists |
||
158 | 15 | ->beforeNormalization() |
|
159 | 15 | ->always(function ($field) { |
|
160 | 9 | $fieldBuilderName = null; |
|
161 | |||
162 | 9 | if (isset($field['builder']) && is_string($field['builder'])) { |
|
163 | 6 | $fieldBuilderName = $field['builder']; |
|
164 | 6 | unset($field['builder']); |
|
165 | 9 | } elseif (is_string($field)) { |
|
166 | 1 | $fieldBuilderName = $field; |
|
167 | 1 | } |
|
168 | |||
169 | 9 | $builderConfig = []; |
|
170 | 9 | if (isset($field['builderConfig'])) { |
|
171 | 5 | if (is_array($field['builderConfig'])) { |
|
172 | 5 | $builderConfig = $field['builderConfig']; |
|
173 | 5 | } |
|
174 | 5 | unset($field['builderConfig']); |
|
175 | 5 | } |
|
176 | |||
177 | 9 | if ($fieldBuilderName) { |
|
178 | 6 | if (!($fieldBuilder = $this->getFieldBuilder($fieldBuilderName))) { |
|
179 | throw new InvalidConfigurationException(sprintf('Field builder "%s" not found.', $fieldBuilderName)); |
||
180 | } |
||
181 | 6 | $buildField = $fieldBuilder->toMappingDefinition($builderConfig); |
|
182 | 6 | $field = is_array($field) ? array_merge($buildField, $field) : $buildField; |
|
183 | 6 | } |
|
184 | |||
185 | 9 | return $field; |
|
186 | 15 | }) |
|
187 | 15 | ->end(); |
|
188 | |||
189 | $prototype |
||
190 | 15 | ->children() |
|
191 | 15 | ->append($this->typeSelection()) |
|
192 | 15 | ->arrayNode('args') |
|
193 | 15 | ->info('Array of possible type arguments. Each entry is expected to be an array with following keys: name (string), type') |
|
194 | 15 | ->useAttributeAsKey('name', false) |
|
195 | 15 | ->prototype('array') |
|
196 | 15 | ->children() |
|
197 | 15 | ->append($this->typeSelection(true)) |
|
198 | 15 | ->scalarNode('description')->end() |
|
199 | 15 | ->append($this->defaultValueSection()) |
|
200 | 15 | ->end() |
|
201 | 15 | ->end() |
|
202 | 15 | ->end() |
|
203 | 15 | ->variableNode('resolve') |
|
204 | 15 | ->info('Value resolver (expression language can be use here)') |
|
205 | 15 | ->end() |
|
206 | 15 | ->append($this->descriptionSection()) |
|
207 | 15 | ->append($this->deprecationReasonSelection()) |
|
208 | 15 | ->variableNode('access') |
|
209 | 15 | ->info('Access control to field (expression language can be use here)') |
|
210 | 15 | ->end() |
|
211 | 15 | ->variableNode('complexity') |
|
212 | 15 | ->info('Custom complexity calculator.') |
|
213 | 15 | ->end() |
|
214 | 15 | ->variableNode('map')->end() |
|
215 | 15 | ->end(); |
|
216 | |||
217 | 15 | if ($withAccess) { |
|
218 | $prototype |
||
219 | 15 | ->children() |
|
220 | 15 | ->variableNode('access') |
|
221 | 15 | ->info('Access control to field (expression language can be use here)') |
|
222 | 15 | ->end() |
|
223 | 15 | ->end(); |
|
224 | 15 | } |
|
225 | |||
226 | 15 | return $node; |
|
227 | } |
||
228 | } |
||
229 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.