Completed
Push — master ( 6ed56d...9a6247 )
by Andrii
03:57
created

Plan::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1.0046

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 4
dl 0
loc 10
ccs 5
cts 6
cp 0.8333
crap 1.0046
rs 10
c 0
b 0
f 0
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-2018, 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\charge\Charge;
15
use hiqdev\php\billing\charge\ChargeInterface;
16
use hiqdev\php\billing\customer\CustomerInterface;
17
use hiqdev\php\billing\price\PriceInterface;
18
19
/**
20
 * Tariff Plan.
21
 *
22
 * @author Andrii Vasyliev <[email protected]>
23
 */
24
class Plan implements PlanInterface
25
{
26
    /**
27
     * @var int
28
     */
29
    protected $id;
30
31
    /**
32
     * @var string
33
     */
34
    protected $name;
35
36
    /**
37
     * @var Plan|null
38
     * XXX not sure to implement
39
     */
40
    protected $parent;
41
42
    /**
43
     * @var CustomerInterface
44
     */
45
    protected $seller;
46
47
    /**
48
     * @var PriceInterface[]
49
     */
50
    protected $prices;
51
52
    /**
53
     * @param int $id
54
     * @param string $name
55 9
     * @param CustomerInterface|null $seller
56
     * @param PriceInterface[] $prices
57
     */
58
    public function __construct(
59
                            $id,
60
                            $name,
61 9
        CustomerInterface   $seller = null,
62 9
                            $prices = null
63 9
    ) {
64 9
        $this->id = $id;
65 9
        $this->name = $name;
66
        $this->seller = $seller;
67
        $this->prices = $prices;
68
    }
69
70
    public function getUniqueId()
71
    {
72
        return $this->getId();
73
    }
74
75
    /**
76
     * @return int|string
77
     */
78
    public function getId()
79
    {
80
        return $this->id;
81
    }
82
83
    /**
84
     * @return string
85
     */
86
    public function getName()
87
    {
88
        return $this->name;
89
    }
90
91
    /**
92
     * @return CustomerInterface
93
     */
94
    public function getSeller(): ?CustomerInterface
95
    {
96
        return $this->seller;
97
    }
98
99
    /**
100
     * @return PlanInterface|null
101
     */
102
    public function getParent(): ?PlanInterface
103
    {
104
        return $this->parent;
105
    }
106
107 2
    /**
108
     * @return bool
109 2
     */
110
    public function hasPrices()
111
    {
112
        return $this->prices !== null;
113
    }
114
115 4
    /**
116
     * @return PriceInterface[]
117 4
     */
118
    public function getPrices()
119
    {
120
        return $this->prices;
121
    }
122
123
    /**
124
     * @param PriceInterface[] $prices
125
     * @throws \Exception
126
     */
127
    public function setPrices(array $prices)
128
    {
129
        if ($this->hasPrices()) {
130
            throw new \Exception('cannot reassign prices for plan');
131
        }
132
        $this->prices = $prices;
133
    }
134
135
    public function jsonSerialize()
136
    {
137
        return get_object_vars($this);
138
    }
139
}
140