Completed
Push — master ( 4a945d...f56bff )
by Andrii
02:24
created

Calculator   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 23
ccs 0
cts 16
cp 0
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
    public function __construct(PlanRepositoryInterface $repository)
23
    {
24
        $this->repository = $repository;
25
    }
26
27
    public function calculateCharges(OrderInterface $order)
28
    {
29
        $plans = $this->repository->findByOrder($order);
0 ignored issues
show
Documentation introduced by
$order is of type object<hiqdev\php\billing\order\OrderInterface>, but the function expects a object<hiqdev\php\billing\plan\OrderInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
30
        $charges = [];
31
        foreach ($order->getActions() as $actionKey => $action) {
32
            if (empty($plans[$actionKey])) {
33
                throw new FailedFindPlan();
34
            }
35
            $charges[$actionKey] = $plans[$actionKey]->calculateCharges($action);
36
        }
37
38
        return $charges;
39
    }
40
}
41