Completed
Push — master ( ac056e...2fe264 )
by David
04:27 queued 01:15
created

MailingList::create()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 9
cts 9
cp 1
rs 9.8666
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * Copyright (C) 2013 Mailgun
7
 *
8
 * This software may be modified and distributed under the terms
9
 * of the MIT license. See the LICENSE file for details.
10
 */
11
12
namespace Mailgun\Model\MailingList;
13
14
use Mailgun\Model\ApiResponse;
15
16
final class MailingList implements ApiResponse
17
{
18
    private $name;
19
    private $address;
20
    private $accessLevel;
21
    private $description;
22
    private $membersCount;
23
    private $createdAt;
24
25 3
    public static function create(array $data): self
26
    {
27 3
        $model = new self();
28 3
        $model->name = $data['name'] ?? null;
29 3
        $model->address = $data['address'] ?? null;
30 3
        $model->accessLevel = $data['access_level'] ?? null;
31 3
        $model->description = $data['description'] ?? null;
32 3
        $model->membersCount = (int) ($data['members_count'] ?? 0);
33 3
        $model->createdAt = isset($data['created_at']) ? new \DateTimeImmutable($data['created_at']) : null;
34
35 3
        return $model;
36
    }
37
38 3
    private function __construct()
39
    {
40 3
    }
41
42
    public function getName(): ?string
43
    {
44
        return $this->name;
45
    }
46
47
    public function getAddress(): ?string
48
    {
49
        return $this->address;
50
    }
51
52 1
    public function getAccessLevel(): ?string
53
    {
54 1
        return $this->accessLevel;
55
    }
56
57
    public function getDescription(): ?string
58
    {
59
        return $this->description;
60
    }
61
62 2
    public function getMembersCount(): int
63
    {
64 2
        return $this->membersCount;
65
    }
66
67
    public function getCreatedAt(): \DateTimeImmutable
68
    {
69
        return $this->createdAt;
70
    }
71
}
72