| Conditions | 7 |
| Paths | 11 |
| Total Lines | 53 |
| Code Lines | 30 |
| 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 |
||
| 57 | public function startSubscription( |
||
| 58 | CustomerInterface $customer, |
||
| 59 | SubscriptionPlan|Plan $plan, |
||
| 60 | Price|PlanPrice $planPrice, |
||
| 61 | ?PaymentCard $paymentDetails = null, |
||
| 62 | int $seatNumbers = 1, |
||
| 63 | ?bool $hasTrial = null, |
||
| 64 | ?int $trialLengthDays = 0, |
||
| 65 | ): Subscription { |
||
| 66 | if (!$plan instanceof Plan) { |
||
| 67 | throw new GeneralException('Invalid type of plan given'); |
||
| 68 | } |
||
| 69 | |||
| 70 | $customerId = $customer->getExternalCustomerReference(); |
||
| 71 | $payload = [ |
||
| 72 | 'subscription_plan' => $plan->getEntityId(), |
||
| 73 | 'price' => $planPrice->getEntityId(), |
||
| 74 | 'seat_numbers' => $seatNumbers, |
||
| 75 | ]; |
||
| 76 | |||
| 77 | if ($paymentDetails) { |
||
| 78 | $payload['payment_details'] = $paymentDetails->getId(); |
||
| 79 | } |
||
| 80 | |||
| 81 | $subscriptionStart = new SubscriptionStartBody($payload); |
||
| 82 | |||
| 83 | try { |
||
| 84 | $response = $this->sdkFactory->createSubscriptionsApi()->customerStartSubscription($subscriptionStart, $customerId); |
||
| 85 | } catch (ApiException $apiException) { |
||
| 86 | if (402 === $apiException->getCode()) { |
||
| 87 | $body = $apiException->getResponseBody(); |
||
| 88 | $json = json_decode($body, true); |
||
| 89 | throw new PaymentFailureException(ChargeFailureReasons::from($json['reason']), previous: $apiException); |
||
| 90 | } |
||
| 91 | |||
| 92 | if (406 === $apiException->getCode()) { |
||
| 93 | throw new NoPaymentDetailsException('No payment details', previous: $apiException); |
||
| 94 | } |
||
| 95 | |||
| 96 | throw new GeneralException(previous: $apiException); |
||
| 97 | } catch (\Throwable $exception) { |
||
| 98 | new GeneralException($exception->getMessage(), previous: $exception); |
||
| 99 | } |
||
| 100 | $subscription = new Subscription(); |
||
| 101 | $subscription->setCustomer($customer); |
||
| 102 | $subscription->setId($response->getId()); |
||
| 103 | $subscription->setValidUntil(new \DateTime($response->getValidUntil())); |
||
| 104 | $subscription->setMainExternalReference($response->getMainExternalReference()); |
||
| 105 | $subscription->setChildExternalReference($response->getChildExternalReference()); |
||
| 106 | |||
| 107 | $this->dispatcher->dispatch(new SubscriptionCreated($subscription), SubscriptionCreated::NAME); |
||
| 108 | |||
| 109 | return $subscription; |
||
| 110 | } |
||
| 145 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths