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 | 62 |
| Code Lines | 41 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 39 |
| 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 |
||
| 59 | 47 | protected function validationSection(int $level): NodeParentInterface |
|
| 60 | { |
||
| 61 | 47 | $node = self::createNode('validation', 'array'); |
|
| 62 | |||
| 63 | $node |
||
| 64 | // allow shorthands |
||
| 65 | 47 | ->beforeNormalization() |
|
| 66 | ->always(function ($value) { |
||
| 67 | 3 | if (\is_string($value)) { |
|
| 68 | // shorthand: cascade or link |
||
| 69 | 2 | return 'cascade' === $value ? ['cascade' => null] : ['link' => $value]; |
|
| 70 | } |
||
| 71 | |||
| 72 | 2 | if (\is_array($value)) { |
|
| 73 | 2 | foreach ($value as $k => $a) { |
|
| 74 | 2 | if (!\is_int($k)) { |
|
| 75 | // validation: { link: ... , constraints: ..., cascade: ... } |
||
| 76 | 1 | return $value; |
|
| 77 | } |
||
| 78 | } |
||
| 79 | // validation: [list of constraints] |
||
| 80 | 2 | return ['constraints' => $value]; |
|
| 81 | } |
||
| 82 | |||
| 83 | 1 | return []; |
|
| 84 | 47 | }) |
|
| 85 | 47 | ->end() |
|
| 86 | 47 | ->children() |
|
| 87 | 47 | ->scalarNode('link') |
|
| 88 | // ->defaultNull() |
||
| 89 | 47 | ->validate() |
|
| 90 | ->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 | 47 | }) |
|
| 97 | 47 | ->thenInvalid('Invalid link provided: "%s".') |
|
| 98 | 47 | ->end() |
|
| 99 | 47 | ->end() |
|
| 100 | 47 | ->variableNode('constraints')->end() |
|
| 101 | 47 | ->end(); |
|
| 102 | |||
| 103 | // Add the 'cascade' option if it's a property level validation section |
||
| 104 | 47 | if (self::VALIDATION_LEVEL_PROPERTY === $level) { |
|
| 105 | $node |
||
| 106 | 47 | ->children() |
|
| 107 | 47 | ->arrayNode('cascade') |
|
| 108 | 47 | ->children() |
|
| 109 | 47 | ->arrayNode('groups') |
|
| 110 | 47 | ->beforeNormalization() |
|
| 111 | 47 | ->castToArray() |
|
| 112 | 47 | ->end() |
|
| 113 | 47 | ->scalarPrototype()->end() |
|
|
|
|||
| 114 | 47 | ->end() |
|
| 115 | 47 | ->end() |
|
| 116 | 47 | ->end() |
|
| 117 | 47 | ->end(); |
|
| 118 | } |
||
| 119 | |||
| 120 | 47 | return $node; |
|
| 121 | } |
||
| 162 |