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

AllResponseItem   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 99
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 12
lcom 0
cbo 0
dl 0
loc 99
ccs 0
cts 25
cp 0
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
B create() 0 10 6
A __construct() 0 8 1
A getId() 0 4 1
A getEvent() 0 4 1
A getTotalCount() 0 4 1
A getTags() 0 4 1
A getCreatedAt() 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
final class AllResponseItem
16
{
17
    /**
18
     * @var string
19
     */
20
    private $id;
21
22
    /**
23
     * @var string
24
     */
25
    private $event;
26
27
    /**
28
     * @var string
29
     */
30
    private $totalCount;
31
32
    /**
33
     * @var string[]
34
     */
35
    private $tags;
36
37
    /**
38
     * @var \DateTime
39
     */
40
    private $createdAt;
41
42
    /**
43
     * @param array $data
44
     *
45
     * @return self
46
     */
47
    public static function create(array $data)
48
    {
49
        return new self(
50
            isset($data['id']) ? $data['id'] : null,
51
            isset($data['event']) ? $data['event'] : null,
52
            isset($data['total_count']) ? $data['total_count'] : null,
53
            isset($data['tags']) ? $data['tags'] : null,
54
            isset($data['created_at']) ? new \DateTime($data['created_at']) : null
0 ignored issues
show
Bug introduced by
It seems like isset($data['created_at'...a['created_at']) : 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...
55
        );
56
    }
57
58
    /**
59
     * @param string    $id
60
     * @param string    $event
61
     * @param string    $totalCount
62
     * @param \string[] $tags
63
     * @param \DateTime $createdAt
64
     */
65
    private function __construct($id, $event, $totalCount, array $tags, \DateTime $createdAt)
66
    {
67
        $this->id = $id;
68
        $this->event = $event;
69
        $this->totalCount = $totalCount;
70
        $this->tags = $tags;
0 ignored issues
show
Documentation Bug introduced by
It seems like $tags of type array<integer,object<string>> is incompatible with the declared type array<integer,string> of property $tags.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
71
        $this->createdAt = $createdAt;
72
    }
73
74
    /**
75
     * @return string
76
     */
77
    public function getId()
78
    {
79
        return $this->id;
80
    }
81
82
    /**
83
     * @return string
84
     */
85
    public function getEvent()
86
    {
87
        return $this->event;
88
    }
89
90
    /**
91
     * @return string
92
     */
93
    public function getTotalCount()
94
    {
95
        return $this->totalCount;
96
    }
97
98
    /**
99
     * @return string[]
100
     */
101
    public function getTags()
102
    {
103
        return $this->tags;
104
    }
105
106
    /**
107
     * @return \DateTime
108
     */
109
    public function getCreatedAt()
110
    {
111
        return $this->createdAt;
112
    }
113
}
114