Completed
Push — master ( da873d...74929b )
by Tobias
03:47
created

TotalResponseItem   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 83
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 10
lcom 0
cbo 0
dl 0
loc 83
ccs 0
cts 21
cp 0
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
B create() 0 9 5
A __construct() 0 7 1
A getTime() 0 4 1
A getAccepted() 0 4 1
A getDelivered() 0 4 1
A getFailed() 0 4 1
1
<?php
2
3
/*
4
 * Copyright (C) 2013-2016 Mailgun
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 Mailgun\Model\Stats;
11
12
/**
13
 * @author Tobias Nyholm <[email protected]>
14
 */
15
class TotalResponseItem
16
{
17
    /**
18
     * @var \DateTime
19
     */
20
    private $time;
21
22
    /**
23
     * @var array
24
     */
25
    private $accepted;
26
27
    /**
28
     * @var array
29
     */
30
    private $delivered;
31
32
    /**
33
     * @var array
34
     */
35
    private $failed;
36
37
    /**
38
     * @param array $data
39
     *
40
     * @return self
41
     */
42
    public static function create(array $data)
43
    {
44
        return new self(
45
            isset($data['time']) ? new \DateTime($data['time']) : null,
0 ignored issues
show
Bug introduced by
It seems like isset($data['time']) ? n...e($data['time']) : null can be null; however, __construct() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
46
            isset($data['accepted']) ? $data['accepted'] : null,
47
            isset($data['delivered']) ? $data['delivered'] : null,
48
            isset($data['failed']) ? $data['failed'] : null
49
        );
50
    }
51
52
    /**
53
     * @param \DateTime $time
54
     * @param array     $accepted
55
     * @param array     $delivered
56
     * @param array     $failed
57
     */
58
    private function __construct(\DateTime $time, array $accepted, array $delivered, array $failed)
59
    {
60
        $this->time = $time;
61
        $this->accepted = $accepted;
62
        $this->delivered = $delivered;
63
        $this->failed = $failed;
64
    }
65
66
    /**
67
     * @return \DateTime
68
     */
69
    public function getTime()
70
    {
71
        return $this->time;
72
    }
73
74
    /**
75
     * @return array
76
     */
77
    public function getAccepted()
78
    {
79
        return $this->accepted;
80
    }
81
82
    /**
83
     * @return array
84
     */
85
    public function getDelivered()
86
    {
87
        return $this->delivered;
88
    }
89
90
    /**
91
     * @return array
92
     */
93
    public function getFailed()
94
    {
95
        return $this->failed;
96
    }
97
}
98