| Conditions | 12 |
| Paths | 514 |
| Total Lines | 54 |
| Code Lines | 28 |
| 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 |
||
| 96 | private function getSubscriptionPostData(Subscription $subscription): array |
||
| 97 | { |
||
| 98 | if (!$subscription->getCustomer()) { |
||
| 99 | throw new UnPostableEntityException('Missing required field `customer`. Make sure you create a new subscription using Subscription::new()'); |
||
| 100 | } |
||
| 101 | |||
| 102 | if (!$subscription->getSubscriptionPlan()) { |
||
| 103 | throw new UnPostableEntityException('Missing required field `subscriptionPlan`. Make sure you create a new subscription using Subscription::new()'); |
||
| 104 | } |
||
| 105 | |||
| 106 | $data = [ |
||
| 107 | 'customer_id' => $subscription->getCustomer()->getId(), |
||
| 108 | 'subscription_plan_id' => $subscription->getSubscriptionPlan()->getId(), |
||
| 109 | ]; |
||
| 110 | |||
| 111 | if ($subscription->getMandate()) { |
||
| 112 | $data['mandate_code'] = $subscription->getMandate()->getCode(); |
||
| 113 | $data['mandate_accepted'] = $subscription->getMandate()->isAccepted(); |
||
| 114 | $data['mandate_accepted_date'] = $subscription->getMandate()->getAcceptedDate()->format(DateTime::ATOM); |
||
| 115 | } |
||
| 116 | |||
| 117 | if ($subscription->getStartDate()) { |
||
| 118 | $data['start_date '] = $subscription->getStartDate()->format(DateTime::ATOM); |
||
| 119 | } |
||
| 120 | |||
| 121 | if ($subscription->getStatus()) { |
||
| 122 | $data['status '] = $subscription->getStatus()->getValue(); |
||
| 123 | } |
||
| 124 | |||
| 125 | if ($subscription->getCancelDate()) { |
||
| 126 | $data['cancel_date '] = $subscription->getCancelDate()->format(DateTime::ATOM); |
||
| 127 | } |
||
| 128 | |||
| 129 | if ($subscription->getResumeDate()) { |
||
| 130 | $data['resume_date '] = $subscription->getResumeDate()->format(DateTime::ATOM); |
||
| 131 | } |
||
| 132 | |||
| 133 | if ($subscription->isConfirmationSent() !== null) { |
||
| 134 | $data['confirmation_sent '] = $subscription->isConfirmationSent(); |
||
| 135 | } |
||
| 136 | |||
| 137 | if ($subscription->getSubscriptionWebhookUrl()) { |
||
| 138 | $data['subscription_webhook_url '] = $subscription->getSubscriptionWebhookUrl(); |
||
| 139 | } |
||
| 140 | |||
| 141 | if ($subscription->getTransactionWebhookUrl()) { |
||
| 142 | $data['transaction_webhook_url '] = $subscription->getTransactionWebhookUrl(); |
||
| 143 | } |
||
| 144 | |||
| 145 | if ($subscription->getSuccessRedirectUrl()) { |
||
| 146 | $data['success_redirect_url '] = $subscription->getSuccessRedirectUrl(); |
||
| 147 | } |
||
| 148 | |||
| 149 | return $data; |
||
| 150 | } |
||
| 174 |
For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example: