| 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 | |||
| 82 |         if ($bill) { | 
            ||
| 83 | //Store the payment  | 
            ||
| 84 | $fee = 0;  | 
            ||
| 85 | $paymentSourceId = $bill->id;  | 
            ||
| 86 | $amount = $bill->amount / 100;  | 
            ||
| 87 | $status = $bill->status;  | 
            ||
| 88 |             if ($status == 'pending_submission') { | 
            ||
| 89 | $status = 'pending';  | 
            ||
| 90 | }  | 
            ||
| 91 | |||
| 92 | //The record payment process will make the necessary record updates  | 
            ||
| 93 | $this->paymentRepository->recordPayment($reason, $user->id, 'gocardless-variable', $paymentSourceId, $amount, $status, $fee, $ref);  | 
            ||
| 94 | |||
| 95 |             if (\Request::wantsJson()) { | 
            ||
| 96 | return \Response::json(['message' => 'The payment was submitted successfully']);  | 
            ||
| 97 | }  | 
            ||
| 98 | |||
| 99 |             \Notification::success("The payment was submitted successfully"); | 
            ||
| 100 |         } else { | 
            ||
| 101 | //something went wrong - we still have the pre auth though  | 
            ||
| 102 | |||
| 103 |             if (\Request::wantsJson()) { | 
            ||
| 104 | return \Response::json(['error' => 'There was a problem charging your account'], 400);  | 
            ||
| 105 | }  | 
            ||
| 106 | |||
| 107 |             \Notification::error("There was a problem charging your account"); | 
            ||
| 108 | }  | 
            ||
| 109 | |||
| 110 | return \Redirect::to($returnPath);  | 
            ||
| 111 | }  | 
            ||
| 112 | |||
| 113 | |||
| 114 | |||
| 115 | private function getDescription($reason)  | 
            ||
| 116 |     { | 
            ||
| 117 |         if ($reason == 'subscription') { | 
            ||
| 118 | return "Monthly Subscription Fee - Manual";  | 
            ||
| 119 |         } elseif ($reason == 'induction') { | 
            ||
| 159 | 
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.