| Conditions | 15 |
| Paths | 28 |
| Total Lines | 94 |
| Code Lines | 65 |
| 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 declare(strict_types=1); |
||
| 30 | public function editable($value, Field $field, HTMLNode $previous): HTMLNode |
||
| 31 | { |
||
| 32 | $validators = $field->getValidators(); |
||
| 33 | |||
| 34 | // add extra classes |
||
| 35 | $input = $previous->get('input'); |
||
| 36 | if (count($input)) { |
||
| 37 | $input[0]->setAttributes([ |
||
| 38 | // TODO ':class' => 'status($v.text)', |
||
| 39 | 'v-model' => '$v.' . implode('.', $input[0]->getAttribute('v-model')) . '.$model' |
||
| 40 | ]); |
||
| 41 | } |
||
| 42 | |||
| 43 | foreach ($validators as $validator => $data) { |
||
| 44 | switch ($validator) { |
||
| 45 | case Datatype::REQUIRED: |
||
| 46 | case Filled::class: |
||
| 47 | $this->setValidations( |
||
| 48 | $field, |
||
| 49 | 'required', |
||
| 50 | 'required' |
||
| 51 | ); |
||
| 52 | break; |
||
| 53 | case Equals::class: |
||
| 54 | // TODO |
||
| 55 | break; |
||
| 56 | |||
| 57 | case In::class: |
||
| 58 | // TODO |
||
| 59 | break; |
||
| 60 | |||
| 61 | case Max::class: |
||
| 62 | $this->setValidations( |
||
| 63 | $field, |
||
| 64 | 'maxValue', |
||
| 65 | 'maxValue(' . $field->getValidatorOption($validator, 'value', '') . ')' |
||
| 66 | ); |
||
| 67 | break; |
||
| 68 | case Min::class: |
||
| 69 | $this->setValidations( |
||
| 70 | $field, |
||
| 71 | 'minValue', |
||
| 72 | 'minValue(' . $field->getValidatorOption($validator, 'value', '') . ')' |
||
| 73 | ); |
||
| 74 | break; |
||
| 75 | |||
| 76 | case MaxLength::class: |
||
| 77 | $this->setValidations( |
||
| 78 | $field, |
||
| 79 | 'maxLength', |
||
| 80 | 'maxLength(' . $field->getValidatorOption($validator, 'value', '') . ')' |
||
| 81 | ); |
||
| 82 | break; |
||
| 83 | case MinLength::class: |
||
| 84 | $this->setValidations( |
||
| 85 | $field, |
||
| 86 | 'minLength', |
||
| 87 | 'minLength(' . $field->getValidatorOption($validator, 'value', '') . ')' |
||
| 88 | ); |
||
| 89 | break; |
||
| 90 | |||
| 91 | case NotIn::class: |
||
| 92 | // TODO |
||
| 93 | break; |
||
| 94 | |||
| 95 | case Password::class: |
||
| 96 | // TODO |
||
| 97 | break; |
||
| 98 | |||
| 99 | case Regex::class: |
||
| 100 | $name = 'regex' . mt_rand(); |
||
| 101 | $this->setValidations( |
||
| 102 | $field, |
||
| 103 | $name, |
||
| 104 | 'helpers.regex(\'' . $name . '\', /' . $field->getValidatorOption($validator, 'value', '') . '/)', |
||
| 105 | 'helpers' |
||
| 106 | ); |
||
| 107 | break; |
||
| 108 | |||
| 109 | case SameAs::class: |
||
| 110 | $target = $field->getValidatorOption($validator, 'value', ''); |
||
| 111 | $locator = $target;// TODO |
||
| 112 | $this->setValidations( |
||
| 113 | $field, |
||
| 114 | 'sameAs', |
||
| 115 | 'sameAs(' . $locator . ')' |
||
| 116 | ); |
||
| 117 | break; |
||
| 118 | default: |
||
| 119 | break; |
||
| 120 | } |
||
| 121 | } |
||
| 122 | |||
| 123 | return $previous; |
||
| 124 | } |
||
| 153 |