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