Completed
Push — master ( d7bed1...8b3382 )
by Andrii
02:16
created

Customer::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 3
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 1
rs 9.4285
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\customer;
12
13
/**
14
 * Customer.
15
 *
16
 * @author Andrii Vasyliev <[email protected]>
17
 */
18
class Customer implements CustomerInterface
19
{
20
    /**
21
     * @var integer
22
     */
23
    protected $id;
24
25
    /**
26
     * @var string
27
     */
28
    protected $login;
29
30
    /**
31
     * @var CustomerInterface
32
     */
33
    protected $seller;
34
35
    /**
36
     * @var Customer[]
37
     */
38
    protected $sellers = [];
39
40 22
    public function __construct($id, $login, CustomerInterface $seller = null)
41
    {
42 22
        $this->id = $id;
43 22
        $this->login = $login;
44 22
        $this->seller = $seller;
45 22
    }
46
47 1
    public function getId()
48
    {
49 1
        return $this->id;
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55 1
    public function getUniqueId()
56
    {
57 1
        return $this->getId() ?: $this->getLogin();
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63
    public function getLogin()
64
    {
65
        return $this->login;
66
    }
67
68
    public function getSeller()
69
    {
70
        return $this->seller;
71
    }
72
73
    public static function fromArray(array $info)
74
    {
75
        if (!empty($info['seller_id']) && !empty($info['seller'])) {
76
            $seller = new static($info['seller_id'], $info['seller']);
77
        } else {
78
            $seller = null;
79
        }
80
81
        return new static($info['id'], $info['login'], $seller);
82
    }
83
84
    public function jsonSerialize()
85
    {
86
        return get_object_vars($this);
87
    }
88
}
89