Completed
Push — master ( 4b0611...da5ccd )
by Tobias
06:14 queued 03:25
created

MailingList::create()   B

Complexity

Conditions 7
Paths 1

Size

Total Lines 11

Duplication

Lines 11
Ratio 100 %

Code Coverage

Tests 9
CRAP Score 7

Importance

Changes 0
Metric Value
dl 11
loc 11
ccs 9
cts 9
cp 1
rs 8.8333
c 0
b 0
f 0
cc 7
nc 1
nop 1
crap 7
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\MailingList;
11
12
use Mailgun\Model\ApiResponse;
13
14
final class MailingList implements ApiResponse
15
{
16
    /**
17
     * @var string
18
     */
19
    private $name;
20
21
    /**
22
     * @var string
23
     */
24
    private $address;
25
26
    /**
27
     * @var string
28
     */
29
    private $accessLevel;
30
31
    /**
32
     * @var string
33
     */
34
    private $description;
35
36
    /**
37
     * @var int
38
     */
39
    private $membersCount;
40
41
    /**
42
     * @var \DateTime
43
     */
44
    private $createdAt;
45
46
    /**
47
     * @param array $data
48
     *
49
     * @return self
50
     */
51 3 View Code Duplication
    public static function create(array $data)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
52
    {
53 3
        return new self(
54 3
            isset($data['name']) ? $data['name'] : null,
55 3
            isset($data['address']) ? $data['address'] : null,
56 3
            isset($data['access_level']) ? $data['access_level'] : null,
57 3
            isset($data['description']) ? $data['description'] : null,
58 3
            isset($data['members_count']) ? $data['members_count'] : null,
59 3
            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...
60 3
        );
61
    }
62
63
    /**
64
     * MailingList constructor.
65
     *
66
     * @param string    $name
67
     * @param string    $address
68
     * @param string    $accessLevel
69
     * @param string    $description
70
     * @param int       $membersCount
71
     * @param \DateTime $createdAt
72
     */
73 3
    private function __construct($name, $address, $accessLevel, $description, $membersCount, \DateTime $createdAt)
74
    {
75 3
        $this->name = $name;
76 3
        $this->address = $address;
77 3
        $this->accessLevel = $accessLevel;
78 3
        $this->description = $description;
79 3
        $this->membersCount = $membersCount;
80 3
        $this->createdAt = $createdAt;
81 3
    }
82
83
    /**
84
     * @return string
85
     */
86
    public function getName()
87
    {
88
        return $this->name;
89
    }
90
91
    /**
92
     * @return string
93
     */
94
    public function getAddress()
95
    {
96
        return $this->address;
97
    }
98
99
    /**
100
     * @return string
101
     */
102 1
    public function getAccessLevel()
103
    {
104 1
        return $this->accessLevel;
105
    }
106
107
    /**
108
     * @return string
109
     */
110
    public function getDescription()
111
    {
112
        return $this->description;
113
    }
114
115
    /**
116
     * @return int
117
     */
118 2
    public function getMembersCount()
119
    {
120 2
        return $this->membersCount;
121
    }
122
123
    /**
124
     * @return \DateTime
125
     */
126
    public function getCreatedAt()
127
    {
128
        return $this->createdAt;
129
    }
130
}
131