| Conditions | 4 |
| Paths | 4 |
| Total Lines | 52 |
| Code Lines | 31 |
| 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 |
||
| 54 | public function store(Request $request) |
||
| 55 | { |
||
| 56 | $request->validate([ |
||
| 57 | 'category' => 'required|numeric', |
||
| 58 | 'name' => [ |
||
| 59 | 'required', |
||
| 60 | 'string', |
||
| 61 | Rule::unique('system_types'), |
||
| 62 | 'regex:/^[a-zA-Z0-9_ ]*$/' |
||
| 63 | ], |
||
| 64 | 'dataOptions' => 'required' |
||
| 65 | |||
| 66 | ]); |
||
| 67 | |||
| 68 | $sysData = SystemTypes::create([ |
||
| 69 | 'cat_id' => $request->category, |
||
| 70 | 'name' => $request->name, |
||
| 71 | 'parent_id' => null, |
||
| 72 | 'folder_location' => str_replace(' ', '_', $request->name) |
||
| 73 | ]); |
||
| 74 | $sysID = $sysData->sys_id; |
||
| 75 | $i = 0; |
||
| 76 | |||
| 77 | foreach($request->dataOptions as $field) |
||
| 78 | { |
||
| 79 | if(!empty($field)) |
||
| 80 | { |
||
| 81 | if(isset($field['value'])) |
||
| 82 | { |
||
| 83 | $id = $field['value']; |
||
| 84 | } |
||
| 85 | else |
||
| 86 | { |
||
| 87 | $newField = SystemCustDataTypes::create([ |
||
| 88 | 'name' => $field['label'] |
||
| 89 | ]); |
||
| 90 | $id = $newField->data_type_id; |
||
| 91 | } |
||
| 92 | |||
| 93 | SystemCustDataFields::create([ |
||
| 94 | 'sys_id' => $sysID, |
||
| 95 | 'data_type_id' => $id, |
||
| 96 | 'order' => $i |
||
| 97 | ]); |
||
| 98 | $i++; |
||
| 99 | } |
||
| 100 | } |
||
| 101 | |||
| 102 | Log::info('New System Created', ['cat_id' => $request->catName, 'sys_name' => $request->name, 'user_id' => Auth::user()->user_id]); |
||
| 103 | $request->session()->flash('success', 'New System Created'); |
||
| 104 | |||
| 105 | return response()->json(['success' => true]); |
||
| 106 | } |
||
| 223 |