Conditions | 14 |
Paths | 16 |
Total Lines | 56 |
Code Lines | 41 |
Lines | 0 |
Ratio | 0 % |
Changes | 6 | ||
Bugs | 0 | Features | 1 |
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 |
||
18 | public function __invoke(Request $request) |
||
19 | { |
||
20 | Stripe\Stripe::setApiKey(\Config::get('services.stripe.secret')); |
||
21 | $plans = Stripe\Plan::all(); |
||
|
|||
22 | $data = request()->all(); |
||
23 | |||
24 | if ($data) { |
||
25 | switch ($data['type']) { |
||
26 | case "customer.subscription.deleted": |
||
27 | $user = User::where('stripe_id', $data['data']['object']['customer'])->first(); |
||
28 | if ($user) { |
||
29 | $user->role_id = 4; |
||
30 | $user->save(); |
||
31 | } |
||
32 | break; |
||
33 | |||
34 | case "customer.subscription.created": |
||
35 | case "customer.subscription.updated": |
||
36 | $user = User::where('stripe_id', $data['data']['object']['customer'])->first(); |
||
37 | if ($user) { |
||
38 | $plan_nickname = $data['data']['object']['plan']['nickname']; |
||
39 | $roles= Role::where('name', strtolower($plan_nickname))->first(); |
||
40 | if ($roles) { |
||
41 | $user->role_id = $roles->id; |
||
42 | $user->save(); |
||
43 | } |
||
44 | } |
||
45 | break; |
||
46 | |||
47 | case "invoice.payment_succeeded": |
||
48 | $user = User::where('stripe_id', $data['data']['object']['customer'])->first(); |
||
49 | if ($user) { |
||
50 | $plan_nickname = $data['data']['object']['lines']['data'][0]['plan']['nickname']; |
||
51 | $roles= Role::where('name', strtolower($plan_nickname))->first(); |
||
52 | if ($roles) { |
||
53 | $user->role_id = $roles->id; |
||
54 | $user->save(); |
||
55 | } |
||
56 | } |
||
57 | break; |
||
58 | case "invoice.payment_failed" : |
||
59 | $user = User::where('stripe_id', $data['data']['object']['customer'])->first(); |
||
60 | if ($user) { |
||
61 | $roles= Role::where('name', strtolower("free"))->first(); |
||
62 | if ($roles) { |
||
63 | $user->role_id = $roles->id; |
||
64 | $user->save(); |
||
65 | } |
||
66 | } |
||
67 | break; |
||
68 | } |
||
69 | } else { |
||
70 | echo 'User not found!'; |
||
71 | } |
||
72 | |||
73 | return true; |
||
74 | } |
||
76 |