Conditions | 20 |
Paths | 567 |
Total Lines | 101 |
Code Lines | 78 |
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 |
||
71 | public function getColumns($table) |
||
72 | { |
||
73 | if(request("modules_id")) { |
||
74 | $module = cb()->find("cb_modules",request("modules_id")); |
||
75 | if($module->last_column_build) { |
||
76 | return response()->json(json_decode($module->last_column_build)); |
||
77 | } |
||
78 | } |
||
79 | |||
80 | $columns = cb()->listAllColumns($table); |
||
81 | $pk = cb()->findPrimaryKey($table); |
||
82 | $result = []; |
||
83 | foreach($columns as $column) { |
||
84 | if($column != $pk) { |
||
85 | |||
86 | // Skip Column |
||
87 | if($column == 'deleted_at') continue; |
||
88 | |||
89 | // Check if any relation table candidate |
||
90 | $optionTable = ""; |
||
91 | if(Str::substr(strtolower($column),-3,3) == "_id") { |
||
92 | $relationTable = Str::substr($column,0,-3); |
||
93 | if(Schema::hasTable($relationTable)) { |
||
94 | $optionTable = $relationTable; |
||
95 | } |
||
96 | }elseif (Str::substr(strtolower($column),0,3) == "id_") { |
||
97 | $relationTable = Str::substr($column,3); |
||
98 | if(Schema::hasTable($relationTable)) { |
||
99 | $optionTable = $relationTable; |
||
100 | } |
||
101 | } |
||
102 | |||
103 | $label = trim(Str::title(str_replace(["id_","_id","_"]," ",$column))); |
||
104 | $label = Str::singular($label); |
||
105 | $type = "text"; |
||
106 | |||
107 | if(Str::contains(strtolower($label),["photo","image","picture","gambar"])) { |
||
108 | $type = "image"; |
||
109 | }elseif (Str::contains(strtolower($label),["email","mail"])) { |
||
110 | $type = "email"; |
||
111 | }elseif (Str::contains(strtolower($label),["description","content","detail"])) { |
||
112 | $type = "wysiwyg"; |
||
113 | }elseif (Str::contains(strtolower($label),["price","money","grand_total","tax"])) { |
||
114 | $type = "money"; |
||
115 | }elseif (Str::contains(strtolower($label),["quantity","qty","total","phone","telp"])) { |
||
116 | $type = "number"; |
||
117 | }elseif (Str::contains(strtolower($label),["date"])) { |
||
118 | $type = "date"; |
||
119 | } |
||
120 | |||
121 | if (Str::substr(strtolower($column),-3,3) == "_id") { |
||
122 | $type = "select_table"; |
||
123 | } elseif (Str::substr($column, -3, 3) == "_at") { |
||
124 | $type = "datetime"; |
||
125 | } elseif (Str::substr($column,0, 3) == "id_") { |
||
126 | $type = "select_table"; |
||
127 | } |
||
128 | |||
129 | $columnAdd = "on"; |
||
130 | $columnEdit = "on"; |
||
131 | $columnMandatory = "on"; |
||
132 | if(in_array($column,['created_at','updated_at'])) { |
||
133 | $columnAdd = ""; |
||
134 | $columnEdit = ""; |
||
135 | $columnMandatory = ""; |
||
136 | } |
||
137 | |||
138 | $result[] = [ |
||
139 | 'column_label'=>$label, |
||
140 | 'column_field'=> $column, |
||
141 | 'column_type'=>$type, |
||
142 | 'column_file_encrypt'=>"on", |
||
143 | 'column_image_width'=>'', |
||
144 | 'column_image_height'=>'', |
||
145 | 'column_option_table'=>$optionTable, |
||
146 | 'column_date_format'=>'', |
||
147 | 'column_text_display_limit'=>150, |
||
148 | 'column_text_max'=>255, |
||
149 | 'column_text_min'=>0, |
||
150 | 'column_money_prefix'=>'', |
||
151 | 'column_money_precision'=>'', |
||
152 | 'column_money_thousand_separator'=>'', |
||
153 | 'column_money_decimal_separator'=>'', |
||
154 | 'column_option_value'=> "", |
||
155 | 'column_option_display'=> "", |
||
156 | 'column_option_sql_condition'=> "", |
||
157 | 'column_options'=> [], |
||
158 | 'column_sql_query'=> "", |
||
159 | 'column_help'=> "", |
||
160 | 'column_mandatory'=> $columnMandatory, |
||
161 | 'column_browse'=> "on", |
||
162 | 'column_detail'=> "on", |
||
163 | 'column_edit'=> $columnEdit, |
||
164 | 'column_add'=> $columnAdd, |
||
165 | "column_filterable"=>"", |
||
166 | "column_foreign"=>"", |
||
167 | 'listTableColumns'=> [] |
||
168 | ]; |
||
169 | } |
||
170 | } |
||
171 | return response()->json($result); |
||
172 | } |
||
281 | } |