We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Conditions | 8 |
| Paths | 2 |
| Total Lines | 64 |
| Code Lines | 41 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 41 |
| CRAP Score | 8 |
| 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 |
||
| 58 | 49 | protected function validationSection(int $level): ArrayNodeDefinition |
|
| 59 | { |
||
| 60 | /** @var ArrayNodeDefinition $node */ |
||
| 61 | 49 | $node = self::createNode('validation', 'array'); |
|
| 62 | |||
| 63 | /** @phpstan-ignore-next-line */ |
||
| 64 | $node |
||
| 65 | // allow shorthands |
||
| 66 | 49 | ->beforeNormalization() |
|
| 67 | 49 | ->always(function ($value) { |
|
| 68 | 3 | if (is_string($value)) { |
|
| 69 | // shorthand: cascade or link |
||
| 70 | 2 | return 'cascade' === $value ? ['cascade' => null] : ['link' => $value]; |
|
| 71 | } |
||
| 72 | |||
| 73 | 2 | if (is_array($value)) { |
|
| 74 | 2 | foreach ($value as $k => $a) { |
|
| 75 | 2 | if (!is_int($k)) { |
|
| 76 | // validation: { link: ... , constraints: ..., cascade: ... } |
||
| 77 | 1 | return $value; |
|
| 78 | } |
||
| 79 | } |
||
| 80 | // validation: [list of constraints] |
||
| 81 | 2 | return ['constraints' => $value]; |
|
| 82 | } |
||
| 83 | |||
| 84 | 1 | return []; |
|
| 85 | 49 | }) |
|
| 86 | 49 | ->end() |
|
| 87 | 49 | ->children() |
|
| 88 | 49 | ->scalarNode('link') |
|
| 89 | 49 | ->validate() |
|
| 90 | 49 | ->ifTrue(function ($link) use ($level) { |
|
| 91 | 1 | if (self::VALIDATION_LEVEL_PROPERTY === $level) { |
|
| 92 | 1 | return !preg_match('/^(?:\\\\?[A-Za-z][A-Za-z\d]+)*[A-Za-z\d]+::(?:[$]?[A-Za-z][A-Za-z_\d]+|[A-Za-z_\d]+\(\))$/m', $link); |
|
| 93 | } else { |
||
| 94 | 1 | return !preg_match('/^(?:\\\\?[A-Za-z][A-Za-z\d]+)*[A-Za-z\d]$/m', $link); |
|
| 95 | } |
||
| 96 | 49 | }) |
|
| 97 | 49 | ->thenInvalid('Invalid link provided: "%s".') |
|
| 98 | 49 | ->end() |
|
| 99 | 49 | ->end() |
|
| 100 | 49 | ->variableNode('constraints')->end() |
|
| 101 | 49 | ->end(); |
|
| 102 | |||
| 103 | // Add the 'cascade' option if it's a property level validation section |
||
| 104 | 49 | if (self::VALIDATION_LEVEL_PROPERTY === $level) { |
|
| 105 | /** @phpstan-ignore-next-line */ |
||
| 106 | $node |
||
| 107 | 49 | ->children() |
|
| 108 | 49 | ->arrayNode('cascade') |
|
| 109 | 49 | ->children() |
|
| 110 | 49 | ->arrayNode('groups') |
|
| 111 | 49 | ->beforeNormalization() |
|
| 112 | 49 | ->castToArray() |
|
| 113 | 49 | ->end() |
|
| 114 | 49 | ->scalarPrototype()->end() |
|
| 115 | 49 | ->end() |
|
| 116 | 49 | ->end() |
|
| 117 | 49 | ->end() |
|
| 118 | 49 | ->end(); |
|
| 119 | } |
||
| 120 | |||
| 121 | 49 | return $node; |
|
| 122 | } |
||
| 247 |