| Conditions | 12 |
| Paths | 12 |
| Total Lines | 31 |
| Code Lines | 26 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 108 | private function validateRule(string $rule, $options): ConstraintViolationList |
||
| 109 | { |
||
| 110 | $errors = new ConstraintViolationList(); |
||
| 111 | |||
| 112 | switch ($rule) { |
||
| 113 | case 'required': |
||
| 114 | $errors = (new RequiredConstraintValidator())->validate($options); |
||
| 115 | break; |
||
| 116 | case 'max': |
||
| 117 | case 'maxlength': |
||
| 118 | case 'maxcheck': |
||
| 119 | $errors = (new MaxConstraintValidator())->validate($options); |
||
| 120 | break; |
||
| 121 | case 'min': |
||
| 122 | case 'minlength': |
||
| 123 | case 'mincheck': |
||
| 124 | $errors = (new MinConstraintValidator())->validate($options); |
||
| 125 | break; |
||
| 126 | case 'equalto': |
||
| 127 | $errors = (new EqualToConstraintValidator())->validate($options); |
||
| 128 | break; |
||
| 129 | case 'type': |
||
| 130 | $errors = (new TypeConstraintValidator())->validate($options); |
||
| 131 | break; |
||
| 132 | case 'length': |
||
| 133 | case 'check': |
||
| 134 | $errors = (new RangeConstraintValidator())->validate($options); |
||
| 135 | break; |
||
| 136 | } |
||
| 137 | |||
| 138 | return $errors; |
||
| 139 | } |
||
| 141 |