| Conditions | 10 |
| Paths | 932 |
| Total Lines | 55 |
| Code Lines | 38 |
| 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 |
||
| 15 | public function advanceSearch($order_no = '', $product_id = '', $expiry = '', |
||
| 16 | $expiryTill = '', $from = '', $till = '', $domain = '') |
||
| 17 | { |
||
| 18 | try { |
||
| 19 | $join = Order::leftJoin('subscriptions', 'orders.id', '=', 'subscriptions.order_id'); |
||
| 20 | if ($order_no) { |
||
| 21 | $join = $join->where('number', $order_no); |
||
| 22 | } |
||
| 23 | if ($product_id) { |
||
| 24 | $join = $join->where('product', $product_id); |
||
| 25 | } |
||
| 26 | if ($expiry) { |
||
| 27 | $expiryFrom = (new BaseSettingsController())->getDateFormat($expiry); |
||
| 28 | $tills = (new BaseSettingsController())->getDateFormat(); |
||
| 29 | |||
| 30 | $tillDate = $this->getTillDate($expiryFrom, $expiryTill, $tills); |
||
| 31 | $join = $join->whereBetween('subscriptions.ends_at', [$expiryFrom, $tillDate]); |
||
| 32 | } |
||
| 33 | |||
| 34 | if ($expiryTill) { |
||
| 35 | $exptill = (new BaseSettingsController())->getDateFormat($expiryTill); |
||
| 36 | $froms = Subscription::first()->ends_at; |
||
| 37 | $fromDate = $this->getFromDate($expiry, $froms); |
||
| 38 | $join = $join->whereBetween('subscriptions.ends_at', [$fromDate, $exptill]); |
||
| 39 | } |
||
| 40 | if ($from) { |
||
| 41 | $fromdate = date_create($from); |
||
| 42 | |||
| 43 | $from = date_format($fromdate, 'Y-m-d H:m:i'); |
||
| 44 | $tills = date('Y-m-d H:m:i'); |
||
| 45 | |||
| 46 | $tillDate = $this->getTillDate($from, $till, $tills); |
||
| 47 | $join = $join->whereBetween('orders.created_at', [$from, $tillDate]); |
||
| 48 | } |
||
| 49 | if ($till) { |
||
| 50 | $tilldate = date_create($till); |
||
| 51 | $till = date_format($tilldate, 'Y-m-d H:m:i'); |
||
| 52 | $froms = Order::first()->created_at; |
||
| 53 | $fromDate = $this->getFromDate($from, $froms); |
||
| 54 | $join = $join->whereBetween('orders.created_at', [$fromDate, $till]); |
||
| 55 | } |
||
| 56 | if ($domain) { |
||
| 57 | if (str_finish($domain, '/')) { |
||
| 58 | $domain = substr_replace($domain, '', -1, 0); |
||
| 59 | } |
||
| 60 | $join = $join->where('domain', 'LIKE', '%'.$domain.'%'); |
||
| 61 | } |
||
| 62 | // dd($join->get()); |
||
| 63 | $join = $join->orderBy('created_at', 'desc') |
||
| 64 | ->select('orders.id', 'orders.created_at', 'client', |
||
| 65 | 'price_override', 'order_status', 'product', 'number', 'serial_key'); |
||
| 66 | |||
| 67 | return $join; |
||
| 68 | } catch (\Exception $ex) { |
||
| 69 | dd($ex); |
||
| 70 | } |
||
| 190 |