Completed
Push — master ( 02e319...091134 )
by Tobias
04:43
created

TotalResponseItem::getComplained()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
/*
4
 * Copyright (C) 2013 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
     * @var array
39
     */
40
    private $complained;
41
42
    /**
43
     * @param array $data
44
     *
45
     * @return self
46
     */
47 4
    public static function create(array $data)
48
    {
49 4
        return new self(
50 4
            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...
51 4
            isset($data['accepted']) ? $data['accepted'] : [],
52 4
            isset($data['delivered']) ? $data['delivered'] : [],
53 4
            isset($data['failed']) ? $data['failed'] : [],
54 4
            isset($data['complained']) ? $data['complained'] : []
55 4
        );
56
    }
57
58
    /**
59
     * @param \DateTime $time
60
     * @param array     $accepted
61
     * @param array     $delivered
62
     * @param array     $failed
63
     * @param array     $complained
64
     */
65 4
    private function __construct(\DateTime $time, array $accepted, array $delivered, array $failed, array $complained)
66
    {
67 4
        $this->time = $time;
68 4
        $this->accepted = $accepted;
69 4
        $this->delivered = $delivered;
70 4
        $this->failed = $failed;
71 4
        $this->complained = $complained;
72 4
    }
73
74
    /**
75
     * @return \DateTime
76
     */
77 1
    public function getTime()
78
    {
79 1
        return $this->time;
80
    }
81
82
    /**
83
     * @return array
84
     */
85
    public function getAccepted()
86
    {
87
        return $this->accepted;
88
    }
89
90
    /**
91
     * @return array
92
     */
93
    public function getDelivered()
94
    {
95
        return $this->delivered;
96
    }
97
98
    /**
99
     * @return array
100
     */
101
    public function getFailed()
102
    {
103
        return $this->failed;
104
    }
105
106
    /**
107
     * @return array
108
     */
109 1
    public function getComplained()
110
    {
111 1
        return $this->complained;
112
    }
113
}
114