| Conditions | 3 |
| Paths | 3 |
| Total Lines | 31 |
| Code Lines | 16 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 16 |
| CRAP Score | 3 |
| Changes | 0 | ||
| 1 | <?php |
||
| 19 | 1 | public function findBestCity(): City |
|
| 20 | { |
||
| 21 | 1 | $results = []; |
|
| 22 | |||
| 23 | 1 | foreach ($this->cities as $current_city) |
|
| 24 | { |
||
| 25 | 1 | $product_totals = []; |
|
| 26 | |||
| 27 | 1 | foreach ($this->products as $current_product) |
|
| 28 | { |
||
| 29 | 1 | $shipping_rule = $current_city->productShippingRule($current_product); |
|
| 30 | |||
| 31 | 1 | $total = $current_product->weight() * $shipping_rule->price(); |
|
| 32 | 1 | $total -= $current_city->saleCostEveryThousandKmPercentage() * $total; |
|
| 33 | 1 | $product_totals[] = $total; |
|
| 34 | } |
||
| 35 | |||
| 36 | 1 | $total = array_sum($product_totals); |
|
| 37 | 1 | $total -= $current_city->loadCost(); |
|
| 38 | |||
| 39 | 1 | $results[$current_city->name()] = $total; |
|
| 40 | } |
||
| 41 | |||
| 42 | 1 | asort($results); |
|
| 43 | |||
| 44 | 1 | end($results); |
|
| 45 | |||
| 46 | 1 | $city_name = key($results); |
|
| 47 | |||
| 48 | 1 | return $this->cityByName($city_name); |
|
| 49 | } |
||
| 50 | |||
| 64 |