| Conditions | 6 |
| Paths | 169 |
| Total Lines | 55 |
| Code Lines | 42 |
| 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 | |||
| 20 | /** |
||
| 21 | *Tax When state is not empty. |
||
| 22 | */ |
||
| 23 | public function getTaxWhenState($user_state, $productid, $origin_state) |
||
| 24 | { |
||
| 25 | $taxes = []; |
||
| 26 | $value = []; |
||
| 27 | $cartController = new CartController(); |
||
| 28 | $c_gst = $user_state->c_gst; |
||
| 29 | $s_gst = $user_state->s_gst; |
||
| 30 | $i_gst = $user_state->i_gst; |
||
| 31 | $ut_gst = $user_state->ut_gst; |
||
| 32 | $state_code = $user_state->state_code; |
||
| 33 | if ($state_code == $origin_state) {//If user and origin state are same |
||
| 34 | $taxClassId = TaxClass::where('name', 'Intra State GST') |
||
| 35 | ->pluck('id')->toArray(); //Get the class Id of state |
||
| 36 | if ($taxClassId) { |
||
| 37 | $taxes = $cartController->getTaxByPriority($taxClassId); |
||
| 38 | $value = $cartController->getValueForSameState($productid, $c_gst, $s_gst, $taxClassId, $taxes); |
||
| 39 | } else { |
||
| 40 | $taxes = [0]; |
||
| 41 | } |
||
| 42 | } elseif ($state_code != $origin_state && $ut_gst == 'NULL') {//If user is from other state |
||
| 43 | |||
| 44 | $taxClassId = TaxClass::where('name', 'Inter State GST') |
||
| 45 | ->pluck('id')->toArray(); //Get the class Id of state |
||
| 46 | if ($taxClassId) { |
||
| 47 | $taxes = $cartController->getTaxByPriority($taxClassId); |
||
| 48 | $value = $cartController->getValueForOtherState($productid, $i_gst, $taxClassId, $taxes); |
||
| 49 | } else { |
||
| 50 | $taxes = [0]; |
||
| 51 | } |
||
| 52 | } elseif ($state_code != $origin_state && $ut_gst != 'NULL') {//if user from Union Territory |
||
| 53 | $taxClassId = TaxClass::where('name', 'Union Territory GST') |
||
| 54 | ->pluck('id')->toArray(); //Get the class Id of state |
||
| 55 | if ($taxClassId) { |
||
| 56 | $taxes = $cartController->getTaxByPriority($taxClassId); |
||
| 57 | $value = $cartController->getValueForUnionTerritory($productid, $c_gst, $ut_gst, $taxClassId, $taxes); |
||
| 58 | } else { |
||
| 59 | $taxes = [0]; |
||
| 60 | } |
||
| 61 | } |
||
| 62 | |||
| 63 | return ['taxes'=>$taxes, 'value'=>$value]; |
||
| 64 | } |
||
| 65 | |||
| 66 | /** |
||
| 67 | *Tax When from other Country. |
||
| 68 | */ |
||
| 69 | public function getTaxWhenOtherCountry($geoip_state, $geoip_country, $productid) |
||
| 70 | { |
||
| 71 | $cartController = new CartController(); |
||
| 72 | $taxClassId = Tax::where('state', $geoip_state) |
||
| 73 | ->orWhere('country', $geoip_country) |
||
| 74 | ->pluck('tax_classes_id')->first(); |
||
| 197 |