Conditions | 11 |
Paths | 16 |
Total Lines | 32 |
Code Lines | 23 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 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 |
||
90 | private function getConstraints(string $inputType, array $inputDefaultOptions, array $inputOptions) |
||
|
|||
91 | { |
||
92 | $ret = []; |
||
93 | |||
94 | $validations = isset($inputDefaultOptions['constraints']) ? $inputDefaultOptions['constraints'] : []; |
||
95 | $validations = array_merge($validations, isset($inputOptions['constraints']) ? $inputOptions['constraints'] : []); |
||
96 | |||
97 | foreach ($validations as $validation => $validationOptions) { |
||
98 | switch ($validation) { |
||
99 | case 'not_blank': |
||
100 | if (isset($inputOptions['required']) && false === $inputOptions['required']) { |
||
101 | // no se setea la validación |
||
102 | } else { |
||
103 | $ret[] = new NotBlank($validationOptions); |
||
104 | } |
||
105 | break; |
||
106 | case 'email': |
||
107 | $ret[] = new Email($validationOptions); |
||
108 | break; |
||
109 | case 'url': |
||
110 | $ret[] = new Url($validationOptions); |
||
111 | break; |
||
112 | case 'length': |
||
113 | $ret[] = new Length($validationOptions); |
||
114 | break; |
||
115 | case 'date': |
||
116 | $ret[] = new Date($validationOptions); |
||
117 | break; |
||
118 | } |
||
119 | } |
||
120 | |||
121 | return $ret; |
||
122 | } |
||
124 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.