| Conditions | 17 |
| Paths | 31 |
| Total Lines | 56 |
| Code Lines | 31 |
| 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 |
||
| 51 | private function getInputValue(TableFieldEntity $field, array $values): mixed |
||
| 52 | { |
||
| 53 | if ($field->isDisabled()) { |
||
| 54 | return false; |
||
| 55 | } |
||
| 56 | |||
| 57 | $fieldId = $this->driver->bracketEscape($field->name); |
||
| 58 | $value = $values['fields'][$fieldId]; |
||
| 59 | |||
| 60 | $userType = $this->userTypes[$field->type] ?? null; |
||
| 61 | $enumValues = $userType?->enums ?? []; |
||
| 62 | if ($field->type === "enum" || count($enumValues) > 0) { |
||
| 63 | $value = $value[0]; |
||
| 64 | if ($value === "orig") { |
||
| 65 | return false; |
||
| 66 | } |
||
| 67 | if ($value === "null") { |
||
| 68 | return "NULL"; |
||
| 69 | } |
||
| 70 | |||
| 71 | $value = substr($value, 4); // 4 - strlen("val-") |
||
| 72 | } |
||
| 73 | |||
| 74 | if ($field->autoIncrement && $value === '') { |
||
| 75 | return null; |
||
| 76 | } |
||
| 77 | |||
| 78 | // The function is not provided for auto-incremented fields or enums. |
||
| 79 | $function = $values['function'][$fieldId] ?? ''; |
||
| 80 | if ($function === 'orig') { |
||
| 81 | return preg_match('~^CURRENT_TIMESTAMP~i', $field->onUpdate) ? |
||
| 82 | $this->driver->escapeId($field->name) : false; |
||
| 83 | } |
||
| 84 | |||
| 85 | if ($function === 'NULL') { |
||
| 86 | return 'NULL'; |
||
| 87 | } |
||
| 88 | |||
| 89 | if ($field->type === 'set') { |
||
| 90 | $value = implode(',', (array)$value); |
||
| 91 | } |
||
| 92 | |||
| 93 | if ($function === 'json') { |
||
| 94 | $function = ''; |
||
|
|
|||
| 95 | $value = json_decode($value, true); |
||
| 96 | //! report errors |
||
| 97 | return is_array($value) ? $value : false; |
||
| 98 | } |
||
| 99 | |||
| 100 | if ($this->utils->isBlob($field) && $this->utils->iniBool('file_uploads')) { |
||
| 101 | $file = $this->page->getFileContents("fields-$fieldId"); |
||
| 102 | //! report errors |
||
| 103 | return is_string($file) ? $this->driver->quoteBinary($file) : false; |
||
| 104 | } |
||
| 105 | |||
| 106 | return $this->page->getUnconvertedFieldValue($field, $value, $function); |
||
| 107 | } |
||
| 129 |