Completed
Push — master ( a7f8c1...61ae9b )
by David
02:12
created

TotalResponse   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 80.95%

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 1
dl 0
loc 52
ccs 17
cts 21
cp 0.8095
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A create() 0 17 5
A getStart() 0 4 1
A getEnd() 0 4 1
A getResolution() 0 4 1
A getStats() 0 4 1
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\Stats;
13
14
use Mailgun\Model\ApiResponse;
15
16
/**
17
 * @author Tobias Nyholm <[email protected]>
18
 */
19
final class TotalResponse implements ApiResponse
20
{
21
    private $start;
22
    private $end;
23
    private $resolution;
24
    private $stats;
25
26 4
    private function __construct()
27
    {
28 4
    }
29
30 4
    public static function create(array $data): self
31
    {
32 4
        $stats = [];
33 4
        if (isset($data['stats'])) {
34 4
            foreach ($data['stats'] as $s) {
35 4
                $stats[] = TotalResponseItem::create($s);
36
            }
37
        }
38
39 4
        $model = new self();
40 4
        $model->start = isset($data['start']) ? new \DateTimeImmutable($data['start']) : null;
41 4
        $model->end = isset($data['end']) ? new \DateTimeImmutable($data['end']) : null;
42 4
        $model->resolution = $data['resolution'] ?? null;
43 4
        $model->stats = $stats;
44
45 4
        return $model;
46
    }
47
48 1
    public function getStart(): ?\DateTimeImmutable
49
    {
50 1
        return $this->start;
51
    }
52
53
    public function getEnd(): ?\DateTimeImmutable
54
    {
55
        return $this->end;
56
    }
57
58
    public function getResolution(): ?string
59
    {
60
        return $this->resolution;
61
    }
62
63
    /**
64
     * @return TotalResponseItem[]
65
     */
66 4
    public function getStats(): array
67
    {
68 4
        return $this->stats;
69
    }
70
}
71