Conditions | 2 |
Paths | 2 |
Total Lines | 54 |
Code Lines | 9 |
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 |
||
70 | public function search(Request $request) |
||
71 | { |
||
72 | // $customers = Customers:: |
||
73 | // with('CustomerSystems.SystemTypes') |
||
74 | // ->get(); |
||
75 | |||
76 | // $custList = []; |
||
77 | // foreach($customers as $cust) |
||
78 | // { |
||
79 | // $sysArr = ''; |
||
80 | // foreach($cust->CustomerSystems as $sys) |
||
81 | // { |
||
82 | // $sysArr .= $sys->SystemTypes->name.'<br />'; |
||
83 | // } |
||
84 | |||
85 | // $custList[] = [ |
||
86 | // 'cust_id' => $cust->cust_id, |
||
87 | // 'name' => $cust->name, |
||
88 | // 'dba' => $cust->dba_name, |
||
89 | // 'city' => $cust->city.', '.$cust->state, |
||
90 | // 'url' => route('customer.details', [$cust->cust_id, urlencode($cust->name)]), |
||
91 | // 'sys' => $sysArr |
||
92 | // ]; |
||
93 | |||
94 | |||
95 | // } |
||
96 | |||
97 | // Log::debug('Route '.Route::currentRouteName().' visited by User ID-'.Auth::user()->user_id); |
||
98 | // Log::debug('Customer Data - ', $custList); |
||
99 | // return response()->json($custList); |
||
100 | |||
101 | |||
102 | // $searchResults = new CustomerCollection( |
||
103 | // Customers::where('cust_id', $request->search) |
||
104 | // ->orWhere('name', $request->search) |
||
105 | // ->orWhere('dba_name', $request->search) |
||
106 | // ->get() |
||
107 | // ); |
||
108 | |||
109 | if($request->search) |
||
110 | { |
||
111 | $searchResults = new CustomerCollection( |
||
112 | Customers::where('cust_id', 'like', '%'.$request->search.'%') |
||
113 | ->orWhere('name', 'like', '%'.$request->search.'%') |
||
114 | ->orWhere('dba_name', 'like', '%' . $request->search . '%') |
||
115 | ->get() |
||
116 | ); |
||
117 | } |
||
118 | else |
||
119 | { |
||
120 | $searchResults = new CustomerCollection(Customers::all()); |
||
121 | } |
||
122 | |||
123 | return $searchResults; |
||
124 | } |
||
169 |