Completed
Push — Lonja/albertg ( 67863a...bda4e5 )
by Albert
07:39 queued 05:26
created

LoadCostsDecorator   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 28
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __invoke() 0 6 1
applyCosts() 0 1 ?
A next() 0 9 2
1
<?php
2
3
namespace Kata\Lonja\Domain\Service\Costs;
4
5
use Kata\Lonja\Domain\Model\Destination;
6
use Kata\Lonja\Domain\Model\Load;
7
8
abstract class LoadCostsDecorator
9
{
10
    private $next_load_cost;
11
12 1
    public function __construct(self $next_load_cost = null)
13
    {
14 1
        $this->next_load_cost = $next_load_cost;
15 1
    }
16
17 1
    public function __invoke(Load $a_load, Destination $a_destination, array $some_price_rules, float $net_benefits, float $previous_costs = 0)
18
    {
19 1
        $costs = $previous_costs + $this->applyCosts($a_load, $a_destination, $some_price_rules, $net_benefits, $previous_costs);
20
21 1
        return $this->next($a_load, $a_destination, $some_price_rules, $net_benefits, $costs);
22
    }
23
24
    abstract protected function applyCosts(Load $a_load, Destination $a_destination, array $some_price_rules, float $net_benefits, float $previous_costs = 0): float;
25
26 1
    private function next($a_load, $a_destination, $some_price_rules, $net_benefits, $costs)
27
    {
28 1
        if (null === $this->next_load_cost)
29
        {
30 1
            return -$costs;
31
        }
32
33 1
        return $this->next_load_cost->__invoke($a_load, $a_destination, $some_price_rules, $net_benefits, $costs);
34
    }
35
}