| Conditions | 3 |
| Paths | 3 |
| Total Lines | 242 |
| Code Lines | 162 |
| 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 |
||
| 19 | public function __invoke(?Request $request = null) |
||
| 20 | { |
||
| 21 | $pp = new PaypalSubscription(); |
||
| 22 | $plans = [ |
||
| 23 | [ |
||
| 24 | 'name' => 'UTY', |
||
| 25 | 'description' => 'Unlimited trees yearly', |
||
| 26 | 'status' => 'ACTIVE', |
||
| 27 | 'billing_cycles' => [ |
||
| 28 | [ |
||
| 29 | 'frequency' => [ |
||
| 30 | 'interval_unit' => 'YEAR', |
||
| 31 | 'interval_count' => '1', |
||
| 32 | ], |
||
| 33 | 'tenure_type' => 'REGULAR', |
||
| 34 | 'sequence' => '1', |
||
| 35 | 'total_cycles' => '12', |
||
| 36 | 'pricing_scheme' => [ |
||
| 37 | 'fixed_price' => [ |
||
| 38 | 'value' => '75', |
||
| 39 | 'currency_code' => 'GBP', |
||
| 40 | ], |
||
| 41 | ], |
||
| 42 | ], |
||
| 43 | ], |
||
| 44 | 'payment_preferences' => [ |
||
| 45 | 'auto_bill_outstanding' => 'true', |
||
| 46 | 'setup_fee' => [ |
||
| 47 | 'value' => '0', |
||
| 48 | 'currency_code' => 'GBP', |
||
| 49 | ], |
||
| 50 | 'setup_fee_failure_action' => 'CONTINUE', |
||
| 51 | 'payment_failure_threshold' => '3', |
||
| 52 | ], |
||
| 53 | 'taxes' => [ |
||
| 54 | 'percentage' => '10', |
||
| 55 | 'inclusive' => false, |
||
| 56 | ], |
||
| 57 | ], |
||
| 58 | |||
| 59 | [ |
||
| 60 | 'name' => 'UTM', |
||
| 61 | 'description' => 'Unlimited trees monthly', |
||
| 62 | 'status' => 'ACTIVE', |
||
| 63 | 'billing_cycles' => [ |
||
| 64 | [ |
||
| 65 | 'frequency' => [ |
||
| 66 | 'interval_unit' => 'MONTH', |
||
| 67 | 'interval_count' => '1', |
||
| 68 | ], |
||
| 69 | 'tenure_type' => 'REGULAR', |
||
| 70 | 'sequence' => '1', |
||
| 71 | 'total_cycles' => '12', |
||
| 72 | 'pricing_scheme' => [ |
||
| 73 | 'fixed_price' => [ |
||
| 74 | 'value' => '7.5', |
||
| 75 | 'currency_code' => 'GBP', |
||
| 76 | ], |
||
| 77 | ], |
||
| 78 | ], |
||
| 79 | ], |
||
| 80 | 'payment_preferences' => [ |
||
| 81 | 'auto_bill_outstanding' => 'true', |
||
| 82 | 'setup_fee' => [ |
||
| 83 | 'value' => '0', |
||
| 84 | 'currency_code' => 'GBP', |
||
| 85 | ], |
||
| 86 | 'setup_fee_failure_action' => 'CONTINUE', |
||
| 87 | 'payment_failure_threshold' => '3', |
||
| 88 | ], |
||
| 89 | 'taxes' => [ |
||
| 90 | 'percentage' => '10', |
||
| 91 | 'inclusive' => false, |
||
| 92 | ], |
||
| 93 | ], |
||
| 94 | |||
| 95 | [ |
||
| 96 | 'name' => 'TTY', |
||
| 97 | 'description' => 'Ten trees yearly', |
||
| 98 | 'status' => 'ACTIVE', |
||
| 99 | 'billing_cycles' => [ |
||
| 100 | [ |
||
| 101 | 'frequency' => [ |
||
| 102 | 'interval_unit' => 'YEAR', |
||
| 103 | 'interval_count' => '1', |
||
| 104 | ], |
||
| 105 | 'tenure_type' => 'REGULAR', |
||
| 106 | 'sequence' => '1', |
||
| 107 | 'total_cycles' => '12', |
||
| 108 | 'pricing_scheme' => [ |
||
| 109 | 'fixed_price' => [ |
||
| 110 | 'value' => '25', |
||
| 111 | 'currency_code' => 'GBP', |
||
| 112 | ], |
||
| 113 | ], |
||
| 114 | ], |
||
| 115 | ], |
||
| 116 | 'payment_preferences' => [ |
||
| 117 | 'auto_bill_outstanding' => 'true', |
||
| 118 | 'setup_fee' => [ |
||
| 119 | 'value' => '0', |
||
| 120 | 'currency_code' => 'GBP', |
||
| 121 | ], |
||
| 122 | 'setup_fee_failure_action' => 'CONTINUE', |
||
| 123 | 'payment_failure_threshold' => '3', |
||
| 124 | ], |
||
| 125 | 'taxes' => [ |
||
| 126 | 'percentage' => '10', |
||
| 127 | 'inclusive' => false, |
||
| 128 | ], |
||
| 129 | ], |
||
| 130 | |||
| 131 | [ |
||
| 132 | 'name' => 'TTM', |
||
| 133 | 'description' => 'Ten trees monthly', |
||
| 134 | 'status' => 'ACTIVE', |
||
| 135 | 'billing_cycles' => [ |
||
| 136 | [ |
||
| 137 | 'frequency' => [ |
||
| 138 | 'interval_unit' => 'MONTH', |
||
| 139 | 'interval_count' => '1', |
||
| 140 | ], |
||
| 141 | 'tenure_type' => 'REGULAR', |
||
| 142 | 'sequence' => '1', |
||
| 143 | 'total_cycles' => '12', |
||
| 144 | 'pricing_scheme' => [ |
||
| 145 | 'fixed_price' => [ |
||
| 146 | 'value' => '2.5', |
||
| 147 | 'currency_code' => 'GBP', |
||
| 148 | ], |
||
| 149 | ], |
||
| 150 | ], |
||
| 151 | ], |
||
| 152 | 'payment_preferences' => [ |
||
| 153 | 'auto_bill_outstanding' => 'true', |
||
| 154 | 'setup_fee' => [ |
||
| 155 | 'value' => '0', |
||
| 156 | 'currency_code' => 'GBP', |
||
| 157 | ], |
||
| 158 | 'setup_fee_failure_action' => 'CONTINUE', |
||
| 159 | 'payment_failure_threshold' => '3', |
||
| 160 | ], |
||
| 161 | 'taxes' => [ |
||
| 162 | 'percentage' => '10', |
||
| 163 | 'inclusive' => false, |
||
| 164 | ], |
||
| 165 | ], |
||
| 166 | |||
| 167 | [ |
||
| 168 | 'name' => 'OTY', |
||
| 169 | 'description' => 'One tree yearly', |
||
| 170 | 'status' => 'ACTIVE', |
||
| 171 | 'billing_cycles' => [ |
||
| 172 | [ |
||
| 173 | 'frequency' => [ |
||
| 174 | 'interval_unit' => 'YEAR', |
||
| 175 | 'interval_count' => '1', |
||
| 176 | ], |
||
| 177 | 'tenure_type' => 'REGULAR', |
||
| 178 | 'sequence' => '1', |
||
| 179 | 'total_cycles' => '12', |
||
| 180 | 'pricing_scheme' => [ |
||
| 181 | 'fixed_price' => [ |
||
| 182 | 'value' => '10', |
||
| 183 | 'currency_code' => 'GBP', |
||
| 184 | ], |
||
| 185 | ], |
||
| 186 | ], |
||
| 187 | ], |
||
| 188 | 'payment_preferences' => [ |
||
| 189 | 'auto_bill_outstanding' => 'true', |
||
| 190 | 'setup_fee' => [ |
||
| 191 | 'value' => '0', |
||
| 192 | 'currency_code' => 'GBP', |
||
| 193 | ], |
||
| 194 | 'setup_fee_failure_action' => 'CONTINUE', |
||
| 195 | 'payment_failure_threshold' => '3', |
||
| 196 | ], |
||
| 197 | 'taxes' => [ |
||
| 198 | 'percentage' => '10', |
||
| 199 | 'inclusive' => false, |
||
| 200 | ], |
||
| 201 | ], |
||
| 202 | |||
| 203 | [ |
||
| 204 | 'name' => 'OTM', |
||
| 205 | 'description' => 'One tree monthly 1', |
||
| 206 | 'status' => 'ACTIVE', |
||
| 207 | 'billing_cycles' => [ |
||
| 208 | [ |
||
| 209 | 'frequency' => [ |
||
| 210 | 'interval_unit' => 'MONTH', |
||
| 211 | 'interval_count' => '1', |
||
| 212 | ], |
||
| 213 | 'tenure_type' => 'REGULAR', |
||
| 214 | 'sequence' => '1', |
||
| 215 | 'total_cycles' => '12', |
||
| 216 | 'pricing_scheme' => [ |
||
| 217 | 'fixed_price' => [ |
||
| 218 | 'value' => '1', |
||
| 219 | 'currency_code' => 'GBP', |
||
| 220 | ], |
||
| 221 | ], |
||
| 222 | ], |
||
| 223 | ], |
||
| 224 | 'payment_preferences' => [ |
||
| 225 | 'auto_bill_outstanding' => 'true', |
||
| 226 | 'setup_fee' => [ |
||
| 227 | 'value' => '0', |
||
| 228 | 'currency_code' => 'GBP', |
||
| 229 | ], |
||
| 230 | 'setup_fee_failure_action' => 'CONTINUE', |
||
| 231 | 'payment_failure_threshold' => '3', |
||
| 232 | ], |
||
| 233 | 'taxes' => [ |
||
| 234 | 'percentage' => '10', |
||
| 235 | 'inclusive' => false, |
||
| 236 | ], |
||
| 237 | ], |
||
| 238 | ]; |
||
| 239 | |||
| 240 | $paypalProduct = new CreateProduct(); |
||
| 241 | $paypalProduct(); |
||
| 242 | |||
| 243 | $product = [ |
||
| 244 | 'product_id' => $paypalProduct->paypal_id, //<--------***** ID DEL PRODUCTO |
||
| 245 | ]; |
||
| 246 | |||
| 247 | foreach ($plans as $plan) { |
||
| 248 | $paypalPlan = PaypalPlan::where('name', $plan['name'])->first(); |
||
| 249 | |||
| 250 | if (! $paypalPlan) { |
||
| 251 | $response = $pp->createPlan($plan, $product); |
||
| 252 | |||
| 253 | PaypalPlan::create([ |
||
| 254 | 'paypal_id' => $response['id'], |
||
| 255 | 'paypal_product_id' => $response['product_id'], |
||
| 256 | 'name' => $response['name'], |
||
| 257 | 'status' => $response['status'], |
||
| 258 | 'description' => $response['description'], |
||
| 259 | 'usage_type' => $response['usage_type'], |
||
| 260 | 'create_time' => Carbon::parse($response['create_time'])->toDateTimeString(), |
||
| 261 | ]); |
||
| 266 |