Completed
Push — master ( 866870...6584d5 )
by Andrii
15:02
created

Plan::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 7
ccs 0
cts 7
cp 0
rs 9.4285
cc 1
eloc 5
nc 1
nop 4
crap 2
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\plan;
12
13
use hiqdev\php\billing\action\ActionInterface;
14
use hiqdev\php\billing\customer\CustomerInterface;
15
use hiqdev\php\billing\price\PriceInterface;
16
use hiqdev\php\billing\target\TargetInterface;
17
18
/**
19
 * Tariff Plan.
20
 *
21
 * @author Andrii Vasyliev <[email protected]>
22
 */
23
class Plan implements EntityInterface
24
{
25
    //  public static function instantiate($row)
0 ignored issues
show
Unused Code Comprehensibility introduced by
55% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
26
    //  {
27
    //      return new static;
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
28
    //  }
29
30
    /**
31
     * @var int
32
     */
33
    protected $id;
34
35
    /**
36
     * @var string
37
     */
38
    protected $name;
39
40
    /**
41
     * @var Plan|null
42
     * XXX not sure to implement
43
     */
44
    protected $parent;
45
46
    /**
47
     * @var CustomerInterface
48
     */
49
    protected $seller;
50
51
    /**
52
     * @var TargetInterface
53
     */
54
    protected $target;
55
56
    /**
57
     * @var PriceInterface[]
58
     */
59
    protected $prices = [];
60
61
    /**
62
     * @param PriceInterface[] $prices
63
     */
64
    public function __construct($id, $name, CustomerInterface $seller, array $prices = [])
65
    {
66
        $this->id = $id;
67
        $this->name = $name;
68
        $this->seller = $seller;
69
        $this->prices = $prices;
70
    }
71
72
    /**
73
     * @return PriceInterface[]
74
     */
75
    public function getPrices()
76
    {
77
        return $this->prices;
78
    }
79
80
    /**
81
     * Calculate charges for given action.
82
     * @param ActionInterface $action
83
     * @return Charge[]
84
     */
85
    public function calculateCharges(ActionInterface $action)
86
    {
87
        $charges = [];
88
        foreach ($this->prices as $price) {
89
            $charge = $price->calculateCharge($action);
0 ignored issues
show
Bug introduced by
The method calculateCharge() does not seem to exist on object<hiqdev\php\billing\price\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...
90
            if ($charge !== null) {
91
                $charges[] = $charge;
92
            }
93
        }
94
95
        return $charges;
96
    }
97
98
    public function jsonSerialize()
99
    {
100
        return get_object_vars($this);
101
    }
102
}
103