Conditions | 17 |
Paths | 1280 |
Total Lines | 89 |
Code Lines | 59 |
Lines | 42 |
Ratio | 47.19 % |
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 namespace GeneaLabs\LaravelMixpanel\Http\Requests; |
||
101 | ['Subscription', ['Status' => 'Canceled', 'Upgraded' => false]], |
||
102 | ['Churn! :-('], |
||
103 | ]; |
||
104 | } |
||
105 | |||
106 | if (count($originalValues)) { |
||
107 | if ($planAmount && $oldPlanAmount) { |
||
108 | if ($planAmount < $oldPlanAmount) { |
||
109 | $profileData = [ |
||
110 | 'Subscription' => $planName, |
||
111 | 'Churned' => (new Carbon($transaction['ended_at'])) |
||
112 | ->timezone('UTC') |
||
113 | ->format('Y-m-d\Th:i:s'), |
||
114 | 'Plan When Churned' => $oldPlanName, |
||
115 | ]; |
||
116 | $trackingData = [ |
||
117 | ['Subscription', [ |
||
118 | 'Upgraded' => false, |
||
119 | 'FromPlan' => $oldPlanName, |
||
120 | 'ToPlan' => $planName, |
||
121 | ]], |
||
122 | ['Churn! :-('], |
||
123 | ]; |
||
124 | } |
||
125 | |||
126 | if ($planAmount > $oldPlanAmount) { |
||
127 | $profileData = [ |
||
128 | 'Subscription' => $planName, |
||
129 | ]; |
||
130 | $trackingData = [ |
||
131 | ['Subscription', [ |
||
132 | 'Upgraded' => true, |
||
133 | 'FromPlan' => $oldPlanName, |
||
134 | 'ToPlan' => $planName, |
||
135 | ]], |
||
136 | ['Unchurn! :-)'], |
||
137 | ]; |
||
138 | } |
||
139 | } else { |
||
140 | if ($planStatus === 'trialing' && ! $oldPlanName) { |
||
141 | $profileData = [ |
||
142 | 'Subscription' => $planName, |
||
143 | ]; |
||
144 | $trackingData = [ |
||
145 | ['Subscription', [ |
||
146 | 'Upgraded' => true, |
||
147 | 'FromPlan' => 'Trial', |
||
148 | 'ToPlan' => $planName, |
||
149 | ]], |
||
150 | ['Unchurn! :-)'], |
||
151 | ]; |
||
152 | } |
||
153 | } |
||
154 | } else { |
||
155 | if ($planStatus === 'active') { |
||
156 | $profileData = [ |
||
157 | 'Subscription' => $planName, |
||
158 | ]; |
||
159 | $trackingData = [ |
||
160 | ['Subscription', ['Status' => 'Created']], |
||
161 | ]; |
||
162 | } |
||
163 | |||
164 | if ($planStatus === 'trialing') { |
||
165 | $profileData = [ |
||
166 | 'Subscription' => 'Trial', |
||
167 | ]; |
||
168 | $trackingData = [ |
||
169 | ['Subscription', ['Status' => 'Trial']], |
||
170 | ]; |
||
171 | } |
||
172 | } |
||
173 | |||
174 | event(new MixpanelEvent($user, $trackingData, 0, $profileData)); |
||
175 | } |
||
176 | |||
177 | private function findStripeCustomerId(array $transaction) |
||
178 | { |
||
179 | if (array_key_exists('customer', $transaction)) { |
||
180 | return $transaction['customer']; |
||
181 | } |
||
182 | |||
183 | if (array_key_exists('object', $transaction) && $transaction['object'] === 'customer') { |
||
184 | return $transaction['id']; |
||
185 | } |
||
186 | |||
187 | if (array_key_exists('subscriptions', $transaction) |
||
188 | && array_key_exists('data', $transaction['subscriptions']) |
||
189 | && array_key_exists(0, $transaction['subscriptions']['data']) |
||
190 | && array_key_exists('customer', $transaction['subscriptions']['data'][0]) |
||
196 |