Conditions | 7 |
Paths | 36 |
Total Lines | 55 |
Code Lines | 32 |
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 namespace BB\Http\Controllers; |
||
64 | |||
65 | /** |
||
66 | * Process a direct debit payment when we have a preauth |
||
67 | * |
||
68 | * @param $amount |
||
69 | * @param $reason |
||
70 | * @param User $user |
||
71 | * @param $ref |
||
72 | * @param $returnPath |
||
73 | * @return mixed |
||
74 | */ |
||
75 | private function handleBill($amount, $reason, $user, $ref, $returnPath) |
||
76 | { |
||
77 | if (is_null($ref)) { |
||
78 | $ref = ''; |
||
79 | } |
||
80 | $bill = $this->goCardless->newBill($user->subscription_id, $amount * 100, $this->goCardless->getNameFromReason($reason)); |
||
81 | //dd($bill); |
||
82 | |||
83 | if ($bill) { |
||
84 | //Store the payment |
||
85 | $fee = 0; |
||
86 | $paymentSourceId = $bill->id; |
||
87 | $amount = $bill->amount / 100; |
||
88 | $status = $bill->status; |
||
89 | if ($status == 'pending_submission') { |
||
90 | $status = 'pending'; |
||
91 | } |
||
92 | |||
93 | //The record payment process will make the necessary record updates |
||
94 | $this->paymentRepository->recordPayment($reason, $user->id, 'gocardless-variable', $paymentSourceId, $amount, $status, $fee, $ref); |
||
95 | |||
96 | if (\Request::wantsJson()) { |
||
97 | return \Response::json(['message' => 'The payment was submitted successfully']); |
||
98 | } |
||
99 | |||
100 | \Notification::success("The payment was submitted successfully"); |
||
101 | } else { |
||
102 | //something went wrong - we still have the pre auth though |
||
103 | |||
104 | if (\Request::wantsJson()) { |
||
105 | return \Response::json(['error' => 'There was a problem charging your account'], 400); |
||
106 | } |
||
107 | |||
108 | \Notification::error("There was a problem charging your account"); |
||
109 | } |
||
110 | |||
111 | return \Redirect::to($returnPath); |
||
112 | } |
||
113 | |||
114 | |||
115 | |||
116 | private function getDescription($reason) |
||
117 | { |
||
118 | if ($reason == 'subscription') { |
||
119 | return "Monthly Subscription Fee - Manual"; |
||
160 |
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.