Completed
Push — master ( e95f12...168b8f )
by Tobias
01:40
created

CustomerContact   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 117
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 48.57%

Importance

Changes 0
Metric Value
wmc 12
lcom 1
cbo 0
dl 0
loc 117
ccs 17
cts 35
cp 0.4857
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
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 4
    public function __construct()
28
    {
29 4
    }
30
31
    /**
32
     * @return string
33
     */
34
    public function getName(): string
35
    {
36
        return $this->name;
37
    }
38
39
    /**
40
     * @param string $name
41
     *
42
     * @return CustomerContact
43
     */
44
    public function withName(string $name)
45
    {
46
        $new = clone $this;
47
        $new->name = $name;
48
49
        return $new;
50
    }
51
52
    /**
53
     * @return string
54
     */
55
    public function getEmail(): string
56
    {
57
        return $this->email;
58
    }
59
60
    /**
61
     * @param string $email
62
     *
63
     * @return CustomerContact
64
     */
65
    public function setEmail(string $email)
66
    {
67
        $new = clone $this;
68
        $new->email = $email;
69
70
        return $new;
71
    }
72
73
    /**
74
     * @return string
75
     */
76
    public function getPhone(): string
77
    {
78
        return $this->phone;
79
    }
80
81
    /**
82
     * @param string $phone
83
     *
84
     * @return CustomerContact
85
     */
86
    public function setPhone(string $phone)
87
    {
88
        $new = clone $this;
89
        $new->phone = $phone;
90
91
        return $new;
92
    }
93
94 2
    public function toArray()
95
    {
96 2
        $data = [];
97 2
        if ($this->name !== null) {
98 2
            $data['name'] = $this->name;
99
        }
100 2
        if ($this->email !== null) {
101 2
            $data['email'] = $this->email;
102
        }
103 2
        if ($this->phone !== null) {
104 2
            $data['phone'] = $this->phone;
105
        }
106
107 2
        return $data;
108
    }
109
110
    /**
111
     * Create an API response object from the HTTP response from the API server.
112
     *
113
     * @param array $data
114
     *
115
     * @return self
116
     */
117 4
    public static function createFromArray(array $data)
118
    {
119 4
        $contact = new self();
120 4
        $contact->name = $data['name'];
121 4
        $contact->email = $data['email'];
122 4
        $contact->phone = $data['phone'];
123
124 4
        return $contact;
125
    }
126
}
127