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

City   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Test Coverage

Coverage 94.12%

Importance

Changes 0
Metric Value
wmc 7
lcom 2
cbo 2
dl 0
loc 47
ccs 16
cts 17
cp 0.9412
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A name() 0 4 1
A productShippingRule() 0 12 3
A loadCost() 0 4 1
A saleCostEveryThousandKmPercentage() 0 5 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