| Conditions | 11 |
| Paths | 12 |
| Total Lines | 63 |
| Code Lines | 30 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| Bugs | 1 | Features | 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 |
||
| 17 | public function __invoke(Request $request) |
||
| 18 | { |
||
| 19 | // $role = Role::where("name", "free")->first(); |
||
| 20 | Stripe\Stripe::setApiKey(\Config::get('services.stripe.secret')); |
||
| 21 | |||
| 22 | $plans = Stripe\Plan::all(); |
||
| 23 | |||
| 24 | $result = []; |
||
| 25 | foreach ($plans as $plan) { |
||
| 26 | if (! $plan->active || $plan->amount == 0) { |
||
| 27 | continue; |
||
| 28 | } |
||
| 29 | |||
| 30 | /* |
||
| 31 | * FREE PLAN |
||
| 32 | */ |
||
| 33 | |||
| 34 | /** |
||
| 35 | * if ($k === 0) { |
||
| 36 | * $row1 = []; |
||
| 37 | * $row1["id"] = $role->id; |
||
| 38 | * $row1["amount"] = 0; |
||
| 39 | * $row1["nickname"] = $role->name; |
||
| 40 | * $row1["title"] = $role->display_name; |
||
| 41 | * $row1["subscribed"] = false; |
||
| 42 | * $result[] = $row1; |
||
| 43 | * }. |
||
| 44 | **/ |
||
| 45 | if (empty($plan->nickname)) { |
||
| 46 | continue; |
||
| 47 | } |
||
| 48 | $row = []; |
||
| 49 | |||
| 50 | $row['id'] = $plan->id; |
||
| 51 | $row['amount'] = $plan->amount; |
||
| 52 | $row['title'] = $plan->nickname; |
||
| 53 | $row['nickname'] = $plan->title; |
||
| 54 | $row['interval'] = $plan->interval; |
||
| 55 | $row['trial_end'] = null; |
||
| 56 | |||
| 57 | $row['features'] = []; |
||
| 58 | $row['features_missing'] = []; |
||
| 59 | $row['metadata'] = [ |
||
| 60 | 'featured' => false, |
||
| 61 | 'description' => 'Missing description!!!', |
||
| 62 | ]; |
||
| 63 | |||
| 64 | foreach ($plan->metadata->toArray() as $key => $value) { |
||
| 65 | if (preg_match('/^feature-missing\d*$/', (string) $key)) { |
||
| 66 | $row['features_missing'][] = $value; |
||
| 67 | } |
||
| 68 | if (preg_match('/^feature\d*$/', (string) $key)) { |
||
| 69 | $row['features'][] = $value; |
||
| 70 | } |
||
| 71 | if ($key == 'featured' && ($value == 1 || $value == 'true')) { |
||
| 72 | $row['metadata']['featured'] = true; |
||
| 73 | } |
||
| 74 | } |
||
| 75 | $row['subscribed'] = false; |
||
| 76 | $result[] = $row; |
||
| 77 | } |
||
| 78 | |||
| 79 | return $result; |
||
|
|
|||
| 80 | } |
||
| 82 |