We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
Conditions | 14 |
Paths | 1 |
Total Lines | 108 |
Code Lines | 78 |
Lines | 0 |
Ratio | 0 % |
Tests | 81 |
CRAP Score | 14 |
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 |
||
119 | 18 | protected function outputFieldsSelection($name) |
|
120 | { |
||
121 | 18 | $builder = new TreeBuilder(); |
|
122 | 18 | $node = $builder->root($name); |
|
123 | $node |
||
124 | 18 | ->isRequired() |
|
125 | 18 | ->requiresAtLeastOneElement(); |
|
126 | |||
127 | /* @var ArrayNodeDefinition $prototype */ |
||
128 | 18 | $prototype = $node->useAttributeAsKey('name', false)->prototype('array'); |
|
129 | |||
130 | $prototype |
||
131 | // build args if argsBuilder exists |
||
132 | 18 | ->beforeNormalization() |
|
133 | ->ifTrue(function ($field) { |
||
134 | 12 | return isset($field['argsBuilder']); |
|
135 | 18 | }) |
|
136 | ->then(function ($field) { |
||
137 | 4 | $argsBuilderName = null; |
|
138 | |||
139 | 4 | if (is_string($field['argsBuilder'])) { |
|
140 | 4 | $argsBuilderName = $field['argsBuilder']; |
|
141 | 4 | } elseif (isset($field['argsBuilder']['builder']) && is_string($field['argsBuilder']['builder'])) { |
|
142 | 1 | $argsBuilderName = $field['argsBuilder']['builder']; |
|
143 | 1 | } |
|
144 | |||
145 | 4 | if ($argsBuilderName) { |
|
146 | 4 | $args = $this->getBuilder($argsBuilderName, static::BUILDER_ARGS_TYPE)->toMappingDefinition([]); |
|
147 | 4 | $field['args'] = isset($field['args']) && is_array($field['args']) ? array_merge($args, $field['args']) : $args; |
|
148 | 4 | } |
|
149 | |||
150 | 4 | unset($field['argsBuilder']); |
|
151 | |||
152 | 4 | return $field; |
|
153 | 18 | }) |
|
154 | 18 | ->end() |
|
155 | // build field if builder exists |
||
156 | 18 | ->beforeNormalization() |
|
157 | ->always(function ($field) { |
||
158 | 12 | $fieldBuilderName = null; |
|
159 | |||
160 | 12 | if (isset($field['builder']) && is_string($field['builder'])) { |
|
161 | 6 | $fieldBuilderName = $field['builder']; |
|
162 | 6 | unset($field['builder']); |
|
163 | 12 | } elseif (is_string($field)) { |
|
164 | 2 | @trigger_error( |
|
165 | 'The builder short syntax (Field: Builder => Field: {builder: Builder}) is deprecated as of 0.7 and will be removed in 0.8. '. |
||
166 | 2 | 'It will be replaced by the field type short syntax (Field: Type => Field: {type: Type})', |
|
167 | E_USER_DEPRECATED |
||
168 | 2 | ); |
|
169 | 2 | $fieldBuilderName = $field; |
|
170 | 2 | } |
|
171 | |||
172 | 12 | $builderConfig = []; |
|
173 | 12 | if (isset($field['builderConfig'])) { |
|
174 | 5 | if (is_array($field['builderConfig'])) { |
|
175 | 5 | $builderConfig = $field['builderConfig']; |
|
176 | 5 | } |
|
177 | 5 | unset($field['builderConfig']); |
|
178 | 5 | } |
|
179 | |||
180 | 12 | if ($fieldBuilderName) { |
|
181 | 6 | $buildField = $this->getBuilder($fieldBuilderName, static::BUILDER_FIELD_TYPE)->toMappingDefinition($builderConfig); |
|
182 | 6 | $field = is_array($field) ? array_merge($buildField, $field) : $buildField; |
|
183 | 6 | } |
|
184 | |||
185 | 12 | return $field; |
|
186 | 18 | }) |
|
187 | 18 | ->end(); |
|
188 | |||
189 | $prototype |
||
190 | 18 | ->children() |
|
191 | 18 | ->append($this->typeSelection()) |
|
192 | 18 | ->arrayNode('args') |
|
193 | 18 | ->info('Array of possible type arguments. Each entry is expected to be an array with following keys: name (string), type') |
|
194 | 18 | ->useAttributeAsKey('name', false) |
|
195 | 18 | ->prototype('array') |
|
196 | // Allow arg type short syntax (Arg: Type => Arg: {type: Type}) |
||
197 | 18 | ->beforeNormalization() |
|
198 | ->ifTrue(function ($options) { |
||
199 | 9 | return is_string($options); |
|
200 | 18 | }) |
|
201 | 18 | ->then(function ($options) { |
|
202 | 1 | return ['type' => $options]; |
|
203 | 18 | }) |
|
204 | 18 | ->end() |
|
205 | 18 | ->children() |
|
206 | 18 | ->append($this->typeSelection(true)) |
|
207 | 18 | ->append($this->descriptionSection()) |
|
208 | 18 | ->append($this->defaultValueSection()) |
|
209 | 18 | ->end() |
|
210 | 18 | ->end() |
|
211 | 18 | ->end() |
|
212 | 18 | ->variableNode('resolve') |
|
213 | 18 | ->info('Value resolver (expression language can be use here)') |
|
214 | 18 | ->end() |
|
215 | 18 | ->append($this->descriptionSection()) |
|
216 | 18 | ->append($this->deprecationReasonSelection()) |
|
217 | 18 | ->variableNode('access') |
|
218 | 18 | ->info('Access control to field (expression language can be use here)') |
|
219 | 18 | ->end() |
|
220 | 18 | ->variableNode('complexity') |
|
221 | 18 | ->info('Custom complexity calculator.') |
|
222 | 18 | ->end() |
|
223 | 18 | ->end(); |
|
224 | |||
225 | 18 | return $node; |
|
226 | } |
||
227 | } |
||
228 |
If you suppress an error, we recommend checking for the error condition explicitly: