Conditions | 10 |
Paths | 10 |
Total Lines | 32 |
Code Lines | 27 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
Bugs | 0 | 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 |
||
102 | public function webhook() |
||
103 | { |
||
104 | $data = request()->all(); |
||
105 | $user = User::where('stripe_id', $data['data']['object']['customer'])->first(); |
||
106 | if ($user) { |
||
107 | $plan_nickname = $data['data']['object']['items']['data'][0]['plan']['nickname']; |
||
108 | foreach ($this->plans as $plan) { |
||
109 | if ($plan->nickname == $plan_nickname) { |
||
110 | switch ($plan->nickname) { |
||
111 | case 'UTY': |
||
112 | $user->syncRoles('UTY'); |
||
113 | break; |
||
114 | case 'UTM': |
||
115 | $user->syncRoles('UTM'); |
||
116 | break; |
||
117 | case 'TTY': |
||
118 | $user->syncRoles('TTY'); |
||
119 | break; |
||
120 | case 'TTM': |
||
121 | $user->syncRoles('TTM'); |
||
122 | break; |
||
123 | case 'OTY': |
||
124 | $user->syncRoles('OTY'); |
||
125 | break; |
||
126 | case 'OTM': |
||
127 | $user->syncRoles('OTM'); |
||
128 | break; |
||
129 | } |
||
130 | } |
||
131 | } |
||
132 | } else { |
||
133 | echo 'User not found!'; |
||
134 | } |
||
137 |