CustomerContact   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 113
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 45.45%

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 0
dl 0
loc 113
ccs 15
cts 33
cp 0.4545
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 4 1
A withName() 0 7 1
A getEmail() 0 4 1
A setEmail() 0 7 1
A getPhone() 0 4 1
A setPhone() 0 7 1
A toArray() 0 15 4
A createFromArray() 0 9 1
1
<?php
2
3
namespace Billogram\Model\Customer;
4
5
use Billogram\Model\CreatableFromArray;
6
7
/**
8
 * @author Ibrahim Hizeoui <[email protected]>
9
 */
10
class CustomerContact implements CreatableFromArray
11
{
12
    /**
13
     * @var string
14
     */
15
    private $name;
16
17
    /**
18
     * @var string
19
     */
20
    private $email;
21
22
    /**
23
     * @var string
24
     */
25
    private $phone;
26
27
    /**
28
     * @return string
29
     */
30
    public function getName(): string
31
    {
32
        return $this->name;
33
    }
34
35
    /**
36
     * @param string $name
37
     *
38
     * @return CustomerContact
39
     */
40
    public function withName(string $name)
41
    {
42
        $new = clone $this;
43
        $new->name = $name;
44
45
        return $new;
46
    }
47
48
    /**
49
     * @return string
50
     */
51
    public function getEmail(): string
52
    {
53
        return $this->email;
54
    }
55
56
    /**
57
     * @param string $email
58
     *
59
     * @return CustomerContact
60
     */
61
    public function setEmail(string $email)
62
    {
63
        $new = clone $this;
64
        $new->email = $email;
65
66
        return $new;
67
    }
68
69
    /**
70
     * @return string
71
     */
72
    public function getPhone(): string
73
    {
74
        return $this->phone;
75
    }
76
77
    /**
78
     * @param string $phone
79
     *
80
     * @return CustomerContact
81
     */
82
    public function setPhone(string $phone)
83
    {
84
        $new = clone $this;
85
        $new->phone = $phone;
86
87
        return $new;
88
    }
89
90 2
    public function toArray()
91
    {
92 2
        $data = [];
93 2
        if (null !== $this->name) {
94 2
            $data['name'] = $this->name;
95
        }
96 2
        if (null !== $this->email) {
97 2
            $data['email'] = $this->email;
98
        }
99 2
        if (null !== $this->phone) {
100 2
            $data['phone'] = $this->phone;
101
        }
102
103 2
        return $data;
104
    }
105
106
    /**
107
     * Create an API response object from the HTTP response from the API server.
108
     *
109
     * @param array $data
110
     *
111
     * @return self
112
     */
113 4
    public static function createFromArray(array $data)
114
    {
115 4
        $contact = new self();
116 4
        $contact->name = $data['name'] ?? null;
117 4
        $contact->email = $data['email'] ?? null;
118 4
        $contact->phone = $data['phone'] ?? null;
119
120 4
        return $contact;
121
    }
122
}
123