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