| Conditions | 14 |
| Paths | 34 |
| Total Lines | 68 |
| Code Lines | 50 |
| 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 |
||
| 17 | static function generateFormConfig($table, $coloms) |
||
|
|
|||
| 18 | { |
||
| 19 | $formArrayString = []; |
||
| 20 | foreach ($coloms as $i => $colName) { |
||
| 21 | //$attribute = []; |
||
| 22 | $input = [ |
||
| 23 | 'label' => self::getLabel($colName), |
||
| 24 | 'name' => $colName, |
||
| 25 | 'type' => '', |
||
| 26 | 'options' => '', |
||
| 27 | 'required' => true, |
||
| 28 | 'validation' => '', |
||
| 29 | 'help' => '', |
||
| 30 | 'placeholder' => '', |
||
| 31 | ]; |
||
| 32 | |||
| 33 | if (FieldDetector::isExceptional($colName)) { |
||
| 34 | continue; |
||
| 35 | } |
||
| 36 | |||
| 37 | $typeData = DbInspector::getFieldTypes($table, $colName); |
||
| 38 | |||
| 39 | list($input['type'], $input['validation'], $input['options']) = self::parseFieldType($typeData); |
||
| 40 | |||
| 41 | if (FieldDetector::isForeignKey($colName)) { |
||
| 42 | list($input['type'], $input['options']) = self::handleForeignKey($colName); |
||
| 43 | } |
||
| 44 | |||
| 45 | if (substr($colName, 0, 3) == 'is_') { |
||
| 46 | $input['type'] = 'radio_dataenum'; |
||
| 47 | $label = ucwords(substr($colName, 3)); |
||
| 48 | $input['options'] = [ |
||
| 49 | 'enum' => ['In '.$label, $label], |
||
| 50 | 'value' => [0, 1], |
||
| 51 | ]; |
||
| 52 | } |
||
| 53 | |||
| 54 | if (FieldDetector::isPassword($colName)) { |
||
| 55 | $input['type'] = 'password'; |
||
| 56 | $input['validation'] = 'min:5|max:32|required'; |
||
| 57 | $input['help'] = cbTrans("text_default_help_password"); |
||
| 58 | }elseif (FieldDetector::isImage($colName)) { |
||
| 59 | $input['type'] = 'upload'; |
||
| 60 | $input['validation'] = 'required|image'; |
||
| 61 | $input['help'] = cbTrans('text_default_help_upload'); |
||
| 62 | }elseif (FieldDetector::isGeographical($colName)) { |
||
| 63 | $input['type'] = 'hidden'; |
||
| 64 | $input['validation'] = 'required|numeric'; |
||
| 65 | }elseif (FieldDetector::isPhone($colName)) { |
||
| 66 | $input['type'] = 'number'; |
||
| 67 | $input['validation'] = 'required|numeric'; |
||
| 68 | $input['placeholder'] = cbTrans('text_default_help_number'); |
||
| 69 | }elseif (FieldDetector::isEmail($colName)) { |
||
| 70 | $input['type'] = 'email'; |
||
| 71 | $input['validation'] = 'require|email|unique:'.$table; |
||
| 72 | $input['placeholder'] = cbTrans('text_default_help_email'); |
||
| 73 | }elseif ($input['type'] == 'text' && FieldDetector::isNameField($colName)) { |
||
| 74 | $input['validation'] = 'required|string|min:3|max:70'; |
||
| 75 | $input['placeholder'] = cbTrans('text_default_help_text'); |
||
| 76 | }elseif ($input['type'] == 'text' && FieldDetector::isUrlField($colName)) { |
||
| 77 | $input['validation'] = 'required|url'; |
||
| 78 | $input['placeholder'] = cbTrans('text_default_help_url'); |
||
| 79 | } |
||
| 80 | |||
| 81 | $formArrayString[] = FileManipulator::stringify($input, " "); |
||
| 82 | } |
||
| 83 | |||
| 84 | return $formArrayString; |
||
| 85 | } |
||
| 142 | } |
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.