| Conditions | 10 | 
| Paths | 512 | 
| Total Lines | 42 | 
| Code Lines | 21 | 
| 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 | ||
| 83 | private function getSubscriptionPatchData(Subscription $subscription): array | ||
| 84 |     { | ||
| 85 | $data = []; | ||
| 86 | |||
| 87 |         if ($subscription->getMandate()) { | ||
| 88 | $data['mandate_accepted'] = $subscription->getMandate()->isAccepted(); | ||
| 89 | $data['mandate_accepted_date'] = $subscription->getMandate()->getAcceptedDate()->format(DateTime::ATOM); | ||
| 90 | } | ||
| 91 | |||
| 92 |         if ($subscription->getStartDate()) { | ||
| 93 | $data['start_date '] = $subscription->getStartDate()->format(DateTime::ATOM); | ||
| 94 | } | ||
| 95 | |||
| 96 |         if ($subscription->getStatus()) { | ||
| 97 | $data['status '] = $subscription->getStatus()->getValue(); | ||
| 98 | } | ||
| 99 | |||
| 100 |         if ($subscription->getCancelDate()) { | ||
| 101 | $data['cancel_date '] = $subscription->getCancelDate()->format(DateTime::ATOM); | ||
| 102 | } | ||
| 103 | |||
| 104 |         if ($subscription->getResumeDate()) { | ||
| 105 | $data['resume_date '] = $subscription->getResumeDate()->format(DateTime::ATOM); | ||
| 106 | } | ||
| 107 | |||
| 108 |         if ($subscription->isConfirmationSent() !== null) { | ||
| 109 | $data['confirmation_sent '] = $subscription->isConfirmationSent(); | ||
| 110 | } | ||
| 111 | |||
| 112 |         if ($subscription->getSubscriptionWebhookUrl()) { | ||
| 113 | $data['subscription_webhook_url '] = $subscription->getSubscriptionWebhookUrl(); | ||
| 114 | } | ||
| 115 | |||
| 116 |         if ($subscription->getTransactionWebhookUrl()) { | ||
| 117 | $data['transaction_webhook_url '] = $subscription->getTransactionWebhookUrl(); | ||
| 118 | } | ||
| 119 | |||
| 120 |         if ($subscription->getSuccessRedirectUrl()) { | ||
| 121 | $data['success_redirect_url '] = $subscription->getSuccessRedirectUrl(); | ||
| 122 | } | ||
| 123 | |||
| 124 | return $data; | ||
| 125 | } | ||
| 127 | 
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: