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

Route::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\Route;
13
14
/**
15
 * @author David Garcia <[email protected]>
16
 */
17
final class Route
18
{
19
    private $id;
20
    private $priority;
21
    private $filter;
22
    private $actions;
23
    private $description;
24
    private $createdAt;
25
26 3
    public static function create(array $data): self
27
    {
28 3
        $model = new self();
29 3
        $model->id = $data['id'] ?? null;
30 3
        $model->priority = $data['priority'] ?? null;
31 3
        $model->filter = $data['expression'] ?? null;
32 3
        $model->actions = Action::createMultiple($data['actions'] ?? []);
33 3
        $model->description = $data['description'] ?? null;
34 3
        $model->createdAt = isset($data['created_at']) ? new \DateTimeImmutable($data['created_at']) : null;
35
36 3
        return $model;
37
    }
38
39 3
    private function __construct()
40
    {
41 3
    }
42
43
    public function getId(): ?string
44
    {
45
        return $this->id;
46
    }
47
48
    /**
49
     * @return Action[]
50
     */
51
    public function getActions(): array
52
    {
53
        return $this->actions;
54
    }
55
56 3
    public function getDescription(): ?string
57
    {
58 3
        return $this->description;
59
    }
60
61
    public function getFilter(): ?string
62
    {
63
        return $this->filter;
64
    }
65
66
    public function getPriority(): ?int
67
    {
68
        return $this->priority;
69
    }
70
71
    public function getCreatedAt(): \DateTimeImmutable
72
    {
73
        return $this->createdAt;
74
    }
75
}
76