Completed
Push — master ( d26128...b08c4e )
by Andrii
03:02
created

Customer::getUniqueId()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

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