| Conditions | 16 |
| Paths | 29 |
| Total Lines | 49 |
| Code Lines | 27 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 44 | private function getInputValue(TableFieldEntity $field, array $values, array $enumValues): mixed |
||
| 45 | { |
||
| 46 | if ($field->isDisabled()) { |
||
|
|
|||
| 47 | return false; |
||
| 48 | } |
||
| 49 | |||
| 50 | $fieldId = $this->driver->bracketEscape($field->name); |
||
| 51 | $value = $values['fields'][$fieldId]; |
||
| 52 | if ($field->type === "enum" || count($enumValues) > 0) { |
||
| 53 | $value = $value[0]; |
||
| 54 | if ($value === "orig") { |
||
| 55 | return false; |
||
| 56 | } |
||
| 57 | if ($value === "null") { |
||
| 58 | return "NULL"; |
||
| 59 | } |
||
| 60 | |||
| 61 | $value = substr($value, 4); // 4 - strlen("val-") |
||
| 62 | } |
||
| 63 | |||
| 64 | if ($field->autoIncrement && $value === '') { |
||
| 65 | return null; |
||
| 66 | } |
||
| 67 | |||
| 68 | // The function is not provided for auto-incremented fields or enums. |
||
| 69 | $function = $values['function'][$fieldId] ?? ''; |
||
| 70 | if ($function === 'orig') { |
||
| 71 | return preg_match('~^CURRENT_TIMESTAMP~i', $field->onUpdate) ? |
||
| 72 | $this->driver->escapeId($field->name) : false; |
||
| 73 | } |
||
| 74 | |||
| 75 | if ($field->type === 'set') { |
||
| 76 | $value = implode(',', (array)$value); |
||
| 77 | } |
||
| 78 | |||
| 79 | if ($function === 'json') { |
||
| 80 | $function = ''; |
||
| 81 | $value = json_decode($value, true); |
||
| 82 | //! report errors |
||
| 83 | return !is_array($value) ? false : $value; |
||
| 84 | } |
||
| 85 | |||
| 86 | if ($this->utils->isBlob($field) && $this->utils->iniBool('file_uploads')) { |
||
| 87 | $file = $this->page->getFileContents("fields-$fieldId"); |
||
| 88 | //! report errors |
||
| 89 | return !is_string($file) ? false : $this->driver->quoteBinary($file); |
||
| 90 | } |
||
| 91 | |||
| 92 | return $this->page->getUnconvertedFieldValue($field, $value, $function); |
||
| 93 | } |
||
| 118 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.