| Conditions | 17 | 
| Paths | 1280 | 
| Total Lines | 98 | 
| Code Lines | 68 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 7 | ||
| 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 namespace GeneaLabs\LaravelMixpanel\Http\Requests; | ||
| 80 | private function recordSubscription(array $transaction, $user, array $originalValues = []) | ||
| 81 |     { | ||
| 82 | $profileData = []; | ||
| 83 | $trackingData = []; | ||
| 84 |         $planStatus = array_key_exists('status', $transaction) ? $transaction['status'] : null; | ||
| 85 | $planName = isset($transaction['plan']['name']) ? $transaction['plan']['name'] : null; | ||
| 86 |         $planStart = array_key_exists('start', $transaction) ? $transaction['start'] : null; | ||
| 87 | $planAmount = isset($transaction['plan']['amount']) ? $transaction['plan']['amount'] : null; | ||
| 88 | $oldPlanName = isset($originalValues['plan']['name']) ? $originalValues['plan']['name'] : null; | ||
| 89 | $oldPlanAmount = isset($originalValues['plan']['amount']) ? $originalValues['plan']['amount'] : null; | ||
| 90 | |||
| 91 |         if ($planStatus === 'canceled') { | ||
| 92 | $profileData = [ | ||
| 93 | 'Subscription' => 'None', | ||
| 94 | 'Churned' => (new Carbon) | ||
| 95 | ->createFromTimestamp($transaction['canceled_at']) | ||
| 96 |                     ->format('Y-m-d\Th:i:s'), | ||
| 97 | 'Plan When Churned' => $planName, | ||
| 98 | 'Paid Lifetime' => (new Carbon) | ||
| 99 | ->createFromTimestampUTC($planStart) | ||
| 100 | ->diffInDays((new Carbon)->createFromTimestamp($transaction['ended_at']) | ||
| 101 |                     ->timezone('UTC')) . ' days' | ||
| 102 | ]; | ||
| 103 | $trackingData = [ | ||
| 104 | 'Subscription' => ['Status' => 'Canceled', 'Upgraded' => false], | ||
| 105 |                 'Churn! :-(' => [], | ||
| 106 | ]; | ||
| 107 | } | ||
| 108 | |||
| 109 |         if (count($originalValues)) { | ||
| 110 |             if ($planAmount && $oldPlanAmount) { | ||
| 111 |                 if ($planAmount < $oldPlanAmount) { | ||
| 112 | $profileData = [ | ||
| 113 | 'Subscription' => $planName, | ||
| 114 | 'Churned' => (new Carbon($transaction['ended_at'])) | ||
| 115 |                             ->timezone('UTC') | ||
| 116 |                             ->format('Y-m-d\Th:i:s'), | ||
| 117 | 'Plan When Churned' => $oldPlanName, | ||
| 118 | ]; | ||
| 119 | $trackingData = [ | ||
| 120 | 'Subscription' => [ | ||
| 121 | 'Upgraded' => false, | ||
| 122 | 'FromPlan' => $oldPlanName, | ||
| 123 | 'ToPlan' => $planName, | ||
| 124 | ], | ||
| 125 |                         'Churn! :-(' => [], | ||
| 126 | ]; | ||
| 127 | } | ||
| 128 | |||
| 129 |                 if ($planAmount > $oldPlanAmount) { | ||
| 130 | $profileData = [ | ||
| 131 | 'Subscription' => $planName, | ||
| 132 | ]; | ||
| 133 | $trackingData = [ | ||
| 134 | 'Subscription' => [ | ||
| 135 | 'Upgraded' => true, | ||
| 136 | 'FromPlan' => $oldPlanName, | ||
| 137 | 'ToPlan' => $planName, | ||
| 138 | ], | ||
| 139 | 'Unchurn! :-)' => [], | ||
| 140 | ]; | ||
| 141 | } | ||
| 142 |             } else { | ||
| 143 |                 if ($planStatus === 'trialing' && ! $oldPlanName) { | ||
| 144 | $profileData = [ | ||
| 145 | 'Subscription' => $planName, | ||
| 146 | ]; | ||
| 147 | $trackingData = [ | ||
| 148 | 'Subscription' => [ | ||
| 149 | 'Upgraded' => true, | ||
| 150 | 'FromPlan' => 'Trial', | ||
| 151 | 'ToPlan' => $planName, | ||
| 152 | ], | ||
| 153 | 'Unchurn! :-)' => [], | ||
| 154 | ]; | ||
| 155 | } | ||
| 156 | } | ||
| 157 |         } else { | ||
| 158 |             if ($planStatus === 'active') { | ||
| 159 | $profileData = [ | ||
| 160 | 'Subscription' => $planName, | ||
| 161 | ]; | ||
| 162 | $trackingData = [ | ||
| 163 | 'Subscription' => ['Status' => 'Created'], | ||
| 164 | ]; | ||
| 165 | } | ||
| 166 | |||
| 167 |             if ($planStatus === 'trialing') { | ||
| 168 | $profileData = [ | ||
| 169 | 'Subscription' => 'Trial', | ||
| 170 | ]; | ||
| 171 | $trackingData = [ | ||
| 172 | 'Subscription' => ['Status' => 'Trial'], | ||
| 173 | ]; | ||
| 174 | } | ||
| 175 | } | ||
| 176 | |||
| 177 | event(new MixpanelEvent($user, $trackingData, 0, $profileData)); | ||
| 178 | } | ||
| 199 | 
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.