Conditions | 8 |
Paths | 32 |
Total Lines | 57 |
Code Lines | 33 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 |
||
63 | public function getPossiblePostage(Parcel $parcel) |
||
64 | { |
||
65 | $return = ArrayList::create(); |
||
66 | $locations = $this->Locations(); |
||
67 | $exclude = $this->Exclusions(); |
||
68 | $country = $parcel->getCountry(); |
||
69 | $region = $parcel->getRegion(); |
||
70 | $value = (float)$parcel->getItems(); |
||
71 | $check = false; |
||
72 | $tax = null; |
||
73 | |||
74 | if ($this->Tax()->exists()) { |
||
75 | $tax = $this->Tax()->ValidTax(); |
||
76 | } |
||
77 | |||
78 | if ($exclude->exists()) { |
||
79 | $exclude = $exclude->filter( |
||
80 | [ |
||
81 | "Regions.CountryCode" => $country, |
||
82 | "Regions.Code" => $region |
||
83 | ] |
||
84 | ); |
||
85 | } |
||
86 | |||
87 | if (!$exclude->exists()) { |
||
88 | if ($locations->exists()) { |
||
89 | $locations = $locations->filter( |
||
90 | [ |
||
91 | "Regions.CountryCode" => $country, |
||
92 | "Regions.Code" => $region |
||
93 | ] |
||
94 | ); |
||
95 | |||
96 | if ($locations->exists()) { |
||
97 | $check = true; |
||
98 | } |
||
99 | } else { |
||
100 | $check = true; |
||
101 | } |
||
102 | } |
||
103 | |||
104 | if ($check) { |
||
105 | $rates = $this->Rates()->filter([ |
||
106 | "Min:LessThanOrEqual" => $value, |
||
107 | "Max:GreaterThanOrEqual" => $value |
||
108 | ]); |
||
109 | |||
110 | foreach ($rates as $rate) { |
||
111 | $return->add(PostageOption::create( |
||
112 | $this->Name, |
||
113 | $rate->Price, |
||
114 | $tax |
||
115 | )); |
||
116 | } |
||
117 | } |
||
118 | |||
119 | return $return; |
||
120 | } |
||
122 |