Completed
Push — Lonja/xserrat ( 69e2b6 )
by Xavier Serrat
17:08 queued 08:59
created

City::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 3
crap 1
1
<?php
2
3
namespace Kata;
4
5
final class City
6
{
7
    private const FIXED_LOAD_COST_IN_EUR = 5;
8
    private const LOAD_COST_IN_EUR_PER_KM = 2;
9
10
    private $name;
11
12
    /** @var ShippingRule[] */
13
    private $shipping_rules;
14
    private $distance;
15
16 1
    public function __construct(string $a_name, array $some_shipping_rules, int $a_distance)
17
    {
18 1
        $this->name           = $a_name;
19 1
        $this->shipping_rules = $some_shipping_rules;
20 1
        $this->distance       = $a_distance;
21 1
    }
22
23 1
    public function name()
24
    {
25 1
        return $this->name;
26
    }
27
28 1
    public function productShippingRule(Product $a_product): ?ShippingRule
29
    {
30 1
        foreach ($this->shipping_rules as $current_shipping_rule)
31
        {
32 1
            if ($current_shipping_rule->product()->equalTo($a_product))
33
            {
34 1
                return $current_shipping_rule;
35
            }
36
        }
37
38
        return null;
39
    }
40
41 1
    public function loadCost(): int
42
    {
43 1
        return self::FIXED_LOAD_COST_IN_EUR + self::LOAD_COST_IN_EUR_PER_KM * $this->distance;
44
    }
45
46 1
    public function saleCostEveryThousandKmPercentage(): float
47
    {
48 1
        $percentage = $this->distance / 100 / 100;
49 1
        return $percentage;
50
    }
51
}
52