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

Customer   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Test Coverage

Coverage 45%

Importance

Changes 0
Metric Value
dl 0
loc 69
ccs 9
cts 20
cp 0.45
rs 10
c 0
b 0
f 0
wmc 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getLogin() 0 3 1
A __construct() 0 5 1
A getUniqueId() 0 3 2
A fromArray() 0 9 3
A getId() 0 3 1
A getSeller() 0 3 1
A jsonSerialize() 0 3 1
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