Customer   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Test Coverage

Coverage 65%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 18
dl 0
loc 72
ccs 13
cts 20
cp 0.65
rs 10
c 1
b 0
f 1
wmc 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getUniqueId() 0 3 2
A getId() 0 3 1
A __construct() 0 5 1
A getLogin() 0 3 1
A fromArray() 0 9 3
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-2020, 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 40
    public function __construct($id, $login, CustomerInterface $seller = null)
41
    {
42 40
        $this->id = $id;
43 40
        $this->login = $login;
44 40
        $this->seller = $seller;
45 40
    }
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 6
    public function getLogin()
64
    {
65 6
        return $this->login;
66
    }
67
68
    /**
69
     * {@inheritdoc}
70
     */
71 5
    public function getSeller()
72
    {
73 5
        return $this->seller;
74
    }
75
76
    public static function fromArray(array $info)
77
    {
78
        if (!empty($info['seller_id']) && !empty($info['seller'])) {
79
            $seller = new static($info['seller_id'], $info['seller']);
80
        } else {
81
            $seller = null;
82
        }
83
84
        return new static($info['id'], $info['login'], $seller);
85
    }
86
87
    public function jsonSerialize(): array
88
    {
89
        return array_filter(get_object_vars($this));
90
    }
91
}
92