Customer   A
last analyzed

Complexity

Total Complexity 17

Size/Duplication

Total Lines 138
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 17
lcom 0
cbo 1
dl 0
loc 138
ccs 0
cts 79
cp 0
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 19 2
B createFromArray() 0 39 8
A getId() 0 4 1
A getUser() 0 4 1
A getEmail() 0 4 1
A getEmailCanonical() 0 4 1
A getFirstName() 0 4 1
A getLastName() 0 4 1
A getGender() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This software may be modified and distributed under the terms
7
 * of the MIT license. See the LICENSE file for details.
8
 */
9
10
namespace FAPI\Sylius\Model\Customer;
11
12
use FAPI\Sylius\Model\CreatableFromArray;
13
14
/**
15
 * @author Kasim Taskin <[email protected]>
16
 */
17
final class Customer implements CreatableFromArray
18
{
19
    /**
20
     * @var int
21
     */
22
    private $id;
23
24
    /**
25
     * @var User
26
     */
27
    private $user;
28
29
    /**
30
     * @var string
31
     */
32
    private $email;
33
34
    /**
35
     * @var string
36
     */
37
    private $emailCanonical;
38
39
    /**
40
     * @var string
41
     */
42
    private $firstName;
43
44
    /**
45
     * @var string
46
     */
47
    private $lastName;
48
49
    /**
50
     * @var string
51
     */
52
    private $gender;
53
54
    /**
55
     * Customer constructor.
56
     */
57
    private function __construct(
58
        int $id,
59
        User $user,
60
        string $email,
61
        string $emailCanonical,
62
        string $firstName,
63
        string $lastName,
64
        string $gender
65
    ) {
66
        $this->id = $id;
67
        if (-1 !== $user->getId()) {
68
            $this->user = $user;
69
        }
70
        $this->email = $email;
71
        $this->emailCanonical = $emailCanonical;
72
        $this->firstName = $firstName;
73
        $this->lastName = $lastName;
74
        $this->gender = $gender;
75
    }
76
77
    /**
78
     * @return Customer
79
     */
80
    public static function createFromArray(array $data): self
81
    {
82
        $id = -1;
83
        if (isset($data['id'])) {
84
            $id = $data['id'];
85
        }
86
87
        $user = User::createFromArray([]);
88
        if (isset($data['user'])) {
89
            $user = User::createFromArray($data['user']);
90
        }
91
92
        $email = '';
93
        if (isset($data['email'])) {
94
            $email = $data['email'];
95
        }
96
97
        $emailCanonical = '';
98
        if (isset($data['emailCanonical'])) {
99
            $emailCanonical = $data['emailCanonical'];
100
        }
101
102
        $firstName = '';
103
        if (isset($data['firstName'])) {
104
            $firstName = $data['firstName'];
105
        }
106
107
        $lastName = '';
108
        if (isset($data['lastName'])) {
109
            $lastName = $data['lastName'];
110
        }
111
112
        $gender = '';
113
        if (isset($data['gender'])) {
114
            $gender = $data['gender'];
115
        }
116
117
        return new self($id, $user, $email, $emailCanonical, $firstName, $lastName, $gender);
118
    }
119
120
    public function getId(): int
121
    {
122
        return $this->id;
123
    }
124
125
    public function getUser(): User
126
    {
127
        return $this->user;
128
    }
129
130
    public function getEmail(): string
131
    {
132
        return $this->email;
133
    }
134
135
    public function getEmailCanonical(): string
136
    {
137
        return $this->emailCanonical;
138
    }
139
140
    public function getFirstName(): string
141
    {
142
        return $this->firstName;
143
    }
144
145
    public function getLastName(): string
146
    {
147
        return $this->lastName;
148
    }
149
150
    public function getGender(): string
151
    {
152
        return $this->gender;
153
    }
154
}
155