Completed
Push — master ( 122bd3...a21908 )
by Dmitry
01:29
created

Calculator   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 91.67%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 23
ccs 11
cts 12
cp 0.9167
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A calculateCharges() 0 13 3
1
<?php
2
/**
3
 * PHP Billing Library
4
 *
5
 * @link      https://github.com/hiqdev/php-billing
6
 * @package   php-billing
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\php\billing\order;
12
13
use hiqdev\php\billing\plan\PlanRepositoryInterface;
14
15
/**
16
 * @author Andrii Vasyliev <[email protected]>
17
 */
18
class Calculator implements CalculatorInterface
19
{
20
    public $repository;
21
22 1
    public function __construct(PlanRepositoryInterface $repository)
23
    {
24 1
        $this->repository = $repository;
25 1
    }
26
27 1
    public function calculateCharges(OrderInterface $order)
28
    {
29 1
        $plans = $this->repository->findByOrder($order);
30 1
        $charges = [];
31 1
        foreach ($order->getActions() as $actionKey => $action) {
32 1
            if (empty($plans[$actionKey])) {
33
                throw new FailedFindPlan();
34
            }
35 1
            $charges[$actionKey] = $plans[$actionKey]->calculateCharges($action);
36 1
        }
37
38 1
        return $charges;
39
    }
40
}
41