Contact::toArray()   A
last analyzed

Complexity

Conditions 5
Paths 16

Size

Total Lines 21
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 10
c 1
b 0
f 0
nc 16
nop 0
dl 0
loc 21
ccs 11
cts 11
cp 1
crap 5
rs 9.6111
1
<?php
2
3
namespace ApiChef\NotifyLK;
4
5
class Contact
6
{
7
    /** @var string */
8
    private $firstName;
9
10
    /** @var string|null */
11
    private $lastName;
12
13
    /** @var string|null */
14
    private $email;
15
16
    /** @var string|null */
17
    private $address;
18
19
    /** @var string|null */
20
    private $group;
21
22 3
    public function __construct(
23
        string $firstName,
24
        string $lastName = null,
25
        string $email = null,
26
        string $address = null,
27
        string $group = null
28
    ) {
29 3
        $this->firstName = $firstName;
30 3
        $this->lastName = $lastName;
31 3
        $this->email = $email;
32 3
        $this->address = $address;
33 3
        $this->group = $group;
34 3
    }
35
36 3
    public function toArray(): array
37
    {
38 3
        $data = ['contact_fname' => $this->firstName];
39
40 3
        if ($this->lastName) {
41 3
            $data['contact_lname'] = $this->lastName;
42
        }
43
44 3
        if ($this->email) {
45 3
            $data['contact_email'] = $this->email;
46
        }
47
48 3
        if ($this->address) {
49 3
            $data['contact_address'] = $this->address;
50
        }
51
52 3
        if ($this->group) {
53 3
            $data['contact_group'] = $this->group;
54
        }
55
56 3
        return $data;
57
    }
58
}
59