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