Completed
Push — master ( 8f4045...77b660 )
by Andrii
04:19
created

Plan::calculateCharges()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 7

Duplication

Lines 12
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 12
loc 12
ccs 0
cts 11
cp 0
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 7
nc 3
nop 1
crap 12
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;
12
13
/**
14
 * Tariff Plan.
15
 *
16
 * @author Andrii Vasyliev <[email protected]>
17
 */
18
class Plan
19
{
20
    /**
21
     * @var int
22
     */
23
    protected $id;
24
25
    /**
26
     * @var string
27
     */
28
    protected $name;
29
30
    /**
31
     * @var Plan|null
32
     * XXX not sure to implement
33
     */
34
    protected $parent;
35
36
    /**
37
     * @var Client
38
     */
39
    protected $client;
40
41
    /**
42
     * @var Target
43
     */
44
    protected $target;
45
46
    /**
47
     * @var PriceInterface[]
48
     */
49
    protected $prices = [];
50
51
    /**
52
     * @param PriceInterface[] $prices
53
     */
54
    public function __construct(array $prices)
55
    {
56
        $this->prices = $prices;
57
    }
58
59
    /**
60
     * @return PriceInterface[]
61
     */
62
    public function getPrices()
63
    {
64
        return $this->prices;
65
    }
66
67
    /**
68
     * Calculate charges for given action.
69
     * @param ActionInterface $action
70
     * @return Charge[]
71
     */
72 View Code Duplication
    public function calculateCharges(ActionInterface $action)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
73
    {
74
        $charges = [];
75
        foreach ($this->prices as $price) {
76
            $charge = $price->calculateCharge($action);
0 ignored issues
show
Bug introduced by
The method calculateCharge() does not seem to exist on object<hiqdev\php\billing\PriceInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
77
            if ($charge !== null) {
78
                $charges[] = $charge;
79
            }
80
        }
81
82
        return $charges;
83
    }
84
}
85