| Conditions | 18 |
| Paths | > 20000 |
| Total Lines | 54 |
| Code Lines | 35 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 31 |
| CRAP Score | 18.8682 |
| 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 |
||
| 69 | 6 | public function loadFieldFromArray(string $column, array $config): FieldInterface |
|
| 70 | { |
||
| 71 | 6 | $className = $this->findFieldClass($config['field']); |
|
| 72 | /** @noinspection IsEmptyFunctionUsageInspection */ |
||
| 73 | 6 | if (!$className) { |
|
|
1 ignored issue
–
show
|
|||
| 74 | 1 | throw new Exception('Field ' . $column . ':' . $config['field'] . ' not found and not available for use'); |
|
| 75 | } |
||
| 76 | 5 | $field = app($className)->init([$column, $config['label']]); |
|
| 77 | 5 | if (isset($config['placeholder'])) { |
|
| 78 | 5 | $field->setPlaceholder($config['placeholder']); |
|
| 79 | } |
||
| 80 | 5 | if (isset($config['default'])) { |
|
| 81 | $field->default($config['default']); |
||
| 82 | } |
||
| 83 | 5 | if (isset($config['index'])) { |
|
| 84 | 5 | $field->index($config['index']); |
|
| 85 | } |
||
| 86 | 5 | if (isset($config['fillable'])) { |
|
| 87 | 5 | $field->fillable($config['fillable']); |
|
| 88 | } |
||
| 89 | 5 | if (isset($config['hidden'])) { |
|
| 90 | 5 | $field->hidden($config['hidden']); |
|
| 91 | } |
||
| 92 | 5 | if (isset($config['references']['table']) && isset($config['references']['field'])) { |
|
| 93 | $field->references($config['references']['table'], $config['references']['field']); |
||
| 94 | } |
||
| 95 | 5 | if (isset($config['filter']['type'])) { |
|
| 96 | 5 | $field->setType($config['filter']['type']); |
|
| 97 | } |
||
| 98 | 5 | if (isset($config['filter']['light'])) { |
|
| 99 | 5 | $field->setLight($config['filter']['light']); |
|
| 100 | } |
||
| 101 | 5 | if (isset($config['filter']['light'])) { |
|
| 102 | 5 | $field->setLight($config['filter']['light']); |
|
| 103 | } |
||
| 104 | 5 | if (isset($config['filter']['nullable'])) { |
|
| 105 | 5 | $field->nullable($config['filter']['nullable']); |
|
| 106 | } |
||
| 107 | 5 | if (isset($config['filter']['unique'])) { |
|
| 108 | 5 | $field->nullable($config['filter']['unique']); |
|
| 109 | } |
||
| 110 | 5 | if (isset($config['filter']['required'])) { |
|
| 111 | 5 | $field->required($config['filter']['required']); |
|
| 112 | } |
||
| 113 | 5 | if (isset($config['filter']['max'])) { |
|
| 114 | $field->max($config['filter']['max']); |
||
| 115 | } |
||
| 116 | 5 | if (isset($config['filter']['min'])) { |
|
| 117 | $field->min($config['filter']['min']); |
||
| 118 | } |
||
| 119 | 5 | if (isset($config['filter']['mask'])) { |
|
| 120 | $field->setMask($config['filter']['mask']); |
||
| 121 | } |
||
| 122 | 5 | return $field; |
|
| 123 | } |
||
| 125 |