We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Conditions | 2 |
| Paths | 1 |
| Total Lines | 74 |
| Code Lines | 60 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 59 |
| CRAP Score | 2 |
| Changes | 2 | ||
| 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 |
||
| 17 | 47 | protected function outputFieldsSelection(string $name = 'fields') |
|
| 18 | { |
||
| 19 | 47 | $node = self::createNode($name); |
|
| 20 | $node |
||
| 21 | 47 | ->isRequired() |
|
| 22 | 47 | ->requiresAtLeastOneElement(); |
|
|
|
|||
| 23 | /* @var ArrayNodeDefinition $prototype */ |
||
| 24 | 47 | $prototype = $node->useAttributeAsKey('name', false)->prototype('array'); |
|
| 25 | |||
| 26 | $prototype |
||
| 27 | // Allow field type short syntax (Field: Type => Field: {type: Type}) |
||
| 28 | 47 | ->beforeNormalization() |
|
| 29 | ->ifTrue(function ($options) { |
||
| 30 | 37 | return \is_string($options); |
|
| 31 | 47 | }) |
|
| 32 | ->then(function ($options) { |
||
| 33 | 3 | return ['type' => $options]; |
|
| 34 | 47 | }) |
|
| 35 | 47 | ->end() |
|
| 36 | 47 | ->validate() |
|
| 37 | ->always(function ($value) { |
||
| 38 | 37 | if (empty($value['validationGroups'])) { |
|
| 39 | 37 | unset($value['validationGroups']); |
|
| 40 | } |
||
| 41 | |||
| 42 | 37 | return $value; |
|
| 43 | 47 | }) |
|
| 44 | 47 | ->end() |
|
| 45 | 47 | ->children() |
|
| 46 | 47 | ->append($this->typeSelection()) |
|
| 47 | 47 | ->append($this->validationSection(self::VALIDATION_LEVEL_CLASS)) |
|
| 48 | 47 | ->arrayNode('validationGroups') |
|
| 49 | 47 | ->prototype('scalar') |
|
| 50 | 47 | ->info('List of validation groups') |
|
| 51 | 47 | ->end() |
|
| 52 | 47 | ->end() |
|
| 53 | 47 | ->arrayNode('args') |
|
| 54 | 47 | ->info('Array of possible type arguments. Each entry is expected to be an array with following keys: name (string), type') |
|
| 55 | 47 | ->useAttributeAsKey('name', false) |
|
| 56 | 47 | ->prototype('array') |
|
| 57 | // Allow arg type short syntax (Arg: Type => Arg: {type: Type}) |
||
| 58 | 47 | ->beforeNormalization() |
|
| 59 | ->ifTrue(function ($options) { |
||
| 60 | 28 | return \is_string($options); |
|
| 61 | 47 | }) |
|
| 62 | ->then(function ($options) { |
||
| 63 | 4 | return ['type' => $options]; |
|
| 64 | 47 | }) |
|
| 65 | 47 | ->end() |
|
| 66 | 47 | ->children() |
|
| 67 | 47 | ->append($this->typeSelection(true)) |
|
| 68 | 47 | ->append($this->descriptionSection()) |
|
| 69 | 47 | ->append($this->defaultValueSection()) |
|
| 70 | 47 | ->append($this->validationSection(self::VALIDATION_LEVEL_PROPERTY)) |
|
| 71 | 47 | ->end() |
|
| 72 | 47 | ->end() |
|
| 73 | 47 | ->end() |
|
| 74 | 47 | ->variableNode('resolve') |
|
| 75 | 47 | ->info('Value resolver (expression language can be used here)') |
|
| 76 | 47 | ->end() |
|
| 77 | 47 | ->append($this->descriptionSection()) |
|
| 78 | 47 | ->append($this->deprecationReasonSelection()) |
|
| 79 | 47 | ->variableNode('access') |
|
| 80 | 47 | ->info('Access control to field (expression language can be used here)') |
|
| 81 | 47 | ->end() |
|
| 82 | 47 | ->variableNode('public') |
|
| 83 | 47 | ->info('Visibility control to field (expression language can be used here)') |
|
| 84 | 47 | ->end() |
|
| 85 | 47 | ->variableNode('complexity') |
|
| 86 | 47 | ->info('Custom complexity calculator.') |
|
| 87 | 47 | ->end() |
|
| 88 | 47 | ->end(); |
|
| 89 | |||
| 90 | 47 | return $node; |
|
| 91 | } |
||
| 108 |