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