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