| Total Complexity | 66 |
| Total Lines | 332 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like ShippingCalculator often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use ShippingCalculator, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 24 | class ShippingCalculator |
||
| 25 | { |
||
| 26 | |||
| 27 | /** |
||
| 28 | * 2 character country code |
||
| 29 | * |
||
| 30 | * @var string |
||
| 31 | */ |
||
| 32 | private $country_code; |
||
| 33 | |||
| 34 | public function setCountryCode($value) |
||
| 35 | { |
||
| 36 | $this->country_code = $value; |
||
| 37 | return $this; |
||
| 38 | } |
||
| 39 | |||
| 40 | public function getCountryCode() |
||
| 41 | { |
||
| 42 | return $this->country_code; |
||
| 43 | } |
||
| 44 | |||
| 45 | /** |
||
| 46 | * Zip/postal code for the search |
||
| 47 | * |
||
| 48 | * @var string |
||
| 49 | */ |
||
| 50 | private $zipcode; |
||
| 51 | |||
| 52 | public function setZipCode($value) |
||
| 53 | { |
||
| 54 | $this->zipcode = $value; |
||
| 55 | return $this; |
||
| 56 | } |
||
| 57 | |||
| 58 | public function getZipCode() |
||
| 59 | { |
||
| 60 | return $this->zipcode; |
||
| 61 | } |
||
| 62 | |||
| 63 | /** |
||
| 64 | * The total cost we will be checking the cart against |
||
| 65 | * |
||
| 66 | * @var Float |
||
| 67 | */ |
||
| 68 | private $cost = 0.0; |
||
| 69 | |||
| 70 | public function setCost($value) |
||
| 71 | { |
||
| 72 | $this->cost = $value; |
||
| 73 | return $this; |
||
| 74 | } |
||
| 75 | |||
| 76 | public function getCost() |
||
| 77 | { |
||
| 78 | return $this->cost; |
||
| 79 | } |
||
| 80 | |||
| 81 | /** |
||
| 82 | * The total weight to check against |
||
| 83 | * |
||
| 84 | * @var Float |
||
| 85 | */ |
||
| 86 | private $weight = 0; |
||
| 87 | |||
| 88 | public function setWeight($value) |
||
| 89 | { |
||
| 90 | $this->weight = $value; |
||
| 91 | return $this; |
||
| 92 | } |
||
| 93 | |||
| 94 | public function getWeight() |
||
| 95 | { |
||
| 96 | return $this->weight; |
||
| 97 | } |
||
| 98 | |||
| 99 | /** |
||
| 100 | * The total numbers of items to check against |
||
| 101 | * |
||
| 102 | * @var Float |
||
| 103 | */ |
||
| 104 | private $items = 0; |
||
| 105 | |||
| 106 | public function setItems($value) |
||
| 107 | { |
||
| 108 | $this->items = $value; |
||
| 109 | return $this; |
||
| 110 | } |
||
| 111 | |||
| 112 | public function getItems() |
||
| 115 | } |
||
| 116 | |||
| 117 | /** |
||
| 118 | * An {@link Discount} object |
||
| 119 | * |
||
| 120 | * @var Discount |
||
| 121 | */ |
||
| 122 | private $discount; |
||
| 123 | |||
| 124 | public function setDiscount(Discount $value) |
||
| 125 | { |
||
| 126 | $this->discount = $value; |
||
| 127 | return $this; |
||
| 128 | } |
||
| 129 | |||
| 130 | public function getDiscount() |
||
| 131 | { |
||
| 132 | return $this->discount; |
||
| 133 | } |
||
| 134 | |||
| 135 | /** |
||
| 136 | * Should we also check for wildcards when doing location/ |
||
| 137 | * postcode searches |
||
| 138 | * |
||
| 139 | * @var Boolean |
||
| 140 | */ |
||
| 141 | private $include_wildcards = true; |
||
| 142 | |||
| 143 | public function setWildcards($value) |
||
| 144 | { |
||
| 145 | $this->include_wildcards = $value; |
||
| 146 | return $this; |
||
| 147 | } |
||
| 148 | |||
| 149 | public function getWildcards() |
||
| 150 | { |
||
| 151 | return $this->include_wildcards; |
||
| 152 | } |
||
| 153 | |||
| 154 | |||
| 155 | /** |
||
| 156 | * Simple constructor that sets the country code and zip. If no |
||
| 157 | * country is set, this class attempts to autodetect. |
||
| 158 | * |
||
| 159 | * @param zipcode string of the zipo/postal code |
||
| 160 | * @param country_code 2 character country code |
||
| 161 | */ |
||
| 162 | public function __construct($zipcode, $country_code = null) |
||
| 172 | } |
||
| 173 | } |
||
| 174 | |||
| 175 | /** |
||
| 176 | * Get the locale of the Member, or if we're not logged in or don't have a locale, use the default one |
||
| 177 | * @return string |
||
| 178 | */ |
||
| 179 | protected function locale() |
||
| 186 | } |
||
| 187 | |||
| 188 | /** |
||
| 189 | * Generate a free postage object we can use in our code. |
||
| 190 | * |
||
| 191 | * @todo This is a little hacky, ideally we need to find a cleaner |
||
| 192 | * way of dealing with postage options that doesn't involve unsaved |
||
| 193 | * database objects. |
||
| 194 | * |
||
| 195 | * @return PostageArea |
||
| 196 | */ |
||
| 197 | public static function CreateFreePostageObject() |
||
| 206 | } |
||
| 207 | |||
| 208 | |||
| 209 | /** |
||
| 210 | * Find relevent postage rates, based on supplied: |
||
| 211 | * - Country |
||
| 212 | * - Zip/postal code |
||
| 213 | * - Weight |
||
| 214 | * - Cost |
||
| 215 | * - Number of Items |
||
| 216 | * |
||
| 217 | * This is returned as an ArrayList that can be looped through. |
||
| 218 | * |
||
| 219 | * @return ArrayList |
||
| 220 | */ |
||
| 221 | public function getPostageAreas() |
||
| 356 | } |
||
| 357 | } |
||
| 358 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths