Passed
Push — master ( bb3e2c...438d9c )
by Andrii
03:09
created

Sale::getCustomer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 1
cp 0
crap 2
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\sale;
12
13
use DateTimeImmutable;
14
use hiqdev\php\billing\customer\CustomerInterface;
15
use hiqdev\php\billing\plan\PlanInterface;
16
use hiqdev\php\billing\target\TargetInterface;
17
use hiqdev\php\billing\Exception\CannotReassignException;
18
19
/**
20
 * Sale.
21
 *
22
 * @author Andrii Vasyliev <[email protected]>
23
 */
24
class Sale implements SaleInterface
25
{
26
    /**
27
     * @var int
28
     */
29
    protected $id;
30
31
    /**
32
     * @var TargetInterface
33
     */
34
    protected $target;
35
36
    /**
37
     * @var CustomerInterface
38
     */
39
    protected $customer;
40
41
    /**
42
     * @var PlanInterface
43
     */
44
    protected $plan;
45
46
    /**
47
     * @var DateTimeImmutable
48
     */
49
    protected $time;
50 11
51
    public function __construct(
52
                            $id,
53
        TargetInterface     $target,
54
        CustomerInterface   $customer,
55
        PlanInterface       $plan,
56
        DateTimeImmutable   $time = null
57 11
    ) {
58 11
        $this->id = $id;
59 11
        $this->target = $target;
60 11
        $this->customer = $customer;
61 11
        $this->plan = $plan;
62 11
        $this->time = $time;
63
    }
64
65
    public function getId()
66
    {
67
        return $this->id;
68
    }
69
70
    public function getTarget()
71
    {
72
        return $this->target;
73
    }
74
75
    public function getCustomer()
76
    {
77
        return $this->customer;
78
    }
79 2
80
    public function getPlan()
81 2
    {
82
        return $this->plan;
83
    }
84 8
85
    public function getTime()
86 8
    {
87
        return $this->time;
88
    }
89
90
    public function hasId()
91
    {
92
        return $this->id !== null;
93
    }
94
95
    public function setId($id)
96
    {
97
        if ((string) $this->id === (string) $id) {
98
            return;
99
        }
100
        if ($this->hasId()) {
101
            throw new CannotReassignException('sale id');
102
        }
103
        $this->id = $id;
104
    }
105
106
    public function jsonSerialize()
107
    {
108
        return array_filter(get_object_vars($this));
109
    }
110
}
111