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 |
||
| 15 | $node |
||
| 16 | 47 | ->isRequired() |
|
| 17 | 47 | ->requiresAtLeastOneElement(); |
|
|
|
|||
| 18 | |||
| 19 | /* @var ArrayNodeDefinition $prototype */ |
||
| 20 | 47 | $prototype = $node->useAttributeAsKey('name', false)->prototype('array'); |
|
| 21 | |||
| 22 | $prototype |
||
| 23 | 47 | ->beforeNormalization() |
|
| 24 | // Allow field type short syntax (Field: Type => Field: {type: Type}) |
||
| 25 | 47 | ->ifTrue(fn ($options) => \is_string($options)) |
|
| 26 | 47 | ->then(fn ($options) => ['type' => $options]) |
|
| 27 | 47 | ->end() |
|
| 28 | 47 | ->validate() |
|
| 29 | // Remove empty entries |
||
| 30 | ->always(function ($value) { |
||
| 31 | 37 | if (empty($value['validationGroups'])) { |
|
| 32 | 37 | unset($value['validationGroups']); |
|
| 33 | } |
||
| 34 | |||
| 35 | 37 | if (empty($value['args'])) { |
|
| 36 | 37 | unset($value['args']); |
|
| 37 | } |
||
| 38 | |||
| 39 | 37 | return $value; |
|
| 40 | 47 | }) |
|
| 41 | 47 | ->end() |
|
| 42 | 47 | ->children() |
|
| 43 | 47 | ->append($this->typeSection()) |
|
| 44 | 47 | ->append($this->validationSection(self::VALIDATION_LEVEL_CLASS)) |
|
| 45 | 47 | ->arrayNode('validationGroups') |
|
| 46 | 47 | ->beforeNormalization() |
|
| 47 | 47 | ->castToArray() |
|
| 48 | 47 | ->end() |
|
| 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 | 47 | ->ifTrue(fn ($options) => \is_string($options)) |
|
| 60 | 47 | ->then(fn ($options) => ['type' => $options]) |
|
| 61 | 47 | ->end() |
|
| 62 | 47 | ->children() |
|
| 63 | 47 | ->append($this->typeSection(true)) |
|
| 64 | 47 | ->append($this->descriptionSection()) |
|
| 65 | 47 | ->append($this->defaultValueSection()) |
|
| 66 | 47 | ->append($this->validationSection(self::VALIDATION_LEVEL_PROPERTY)) |
|
| 67 | 47 | ->end() |
|
| 68 | 47 | ->end() |
|
| 69 | 47 | ->end() |
|
| 70 | 47 | ->variableNode('resolve') |
|
| 71 | 47 | ->info('Value resolver (expression language can be used here)') |
|
| 72 | 47 | ->end() |
|
| 73 | 47 | ->append($this->descriptionSection()) |
|
| 74 | 47 | ->append($this->deprecationReasonSection()) |
|
| 75 | 47 | ->variableNode('access') |
|
| 76 | 47 | ->info('Access control to field (expression language can be used here)') |
|
| 77 | 47 | ->end() |
|
| 78 | 47 | ->variableNode('public') |
|
| 79 | 47 | ->info('Visibility control to field (expression language can be used here)') |
|
| 80 | 47 | ->end() |
|
| 81 | 47 | ->variableNode('complexity') |
|
| 82 | 47 | ->info('Custom complexity calculator.') |
|
| 83 | 47 | ->end() |
|
| 84 | 47 | ->end(); |
|
| 85 | |||
| 86 | 47 | return $node; |
|
| 87 | } |
||
| 88 | |||
| 89 | 47 | protected function fieldsBuilderSection() |
|
| 104 |