| Conditions | 11 |
| Paths | 38 |
| Total Lines | 35 |
| Code Lines | 19 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 132 |
| 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 |
||
| 54 | protected function handleCustomerSubscriptionUpdated(array $payload): Response |
||
| 55 | { |
||
| 56 | $user = Users::findFirstByStripeId($payload['data']['object']['customer']); |
||
|
1 ignored issue
–
show
|
|||
| 57 | if ($user) { |
||
| 58 | $data = $payload['data']['object']; |
||
| 59 | //get the current subscription they are updating |
||
| 60 | $subscription = $user->getAllSubscriptions('stripe_id =' . $data['id']); |
||
| 61 | |||
| 62 | if (is_object($subscription)) { |
||
| 63 | // Quantity... |
||
| 64 | if (isset($data['quantity'])) { |
||
| 65 | $subscription->quantity = $data['quantity']; |
||
| 66 | } |
||
| 67 | // Plan... |
||
| 68 | if (isset($data['plan']['id'])) { |
||
| 69 | $subscription->stripe_plan = $data['plan']['id']; |
||
| 70 | } |
||
| 71 | // Trial ending date... |
||
| 72 | if (isset($data['trial_end'])) { |
||
| 73 | $trial_ends = Carbon::createFromTimestamp($data['trial_end']); |
||
| 74 | if (!$subscription->trial_ends_at || $subscription->trial_ends_at->ne($trial_ends)) { |
||
| 75 | $subscription->trial_ends_at = $trial_ends; |
||
| 76 | } |
||
| 77 | } |
||
| 78 | // Cancellation date... |
||
| 79 | if (isset($data['cancel_at_period_end']) && $data['cancel_at_period_end']) { |
||
| 80 | $subscription->ends_at = $subscription->onTrial() |
||
| 81 | ? $subscription->trial_ends_at |
||
| 82 | : Carbon::createFromTimestamp($data['current_period_end']); |
||
| 83 | } |
||
| 84 | |||
| 85 | $subscription->update(); |
||
| 86 | } |
||
| 87 | } |
||
| 88 | return $this->response(['Webhook Handled']); |
||
| 89 | } |
||
| 197 |