Completed
Push — master ( 43a76d...75ce5f )
by David
01:41
created

Preview::getQuantity()   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
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\EmailValidationV4;
13
14
use DateTimeImmutable;
15
use Mailgun\Model\ApiResponse;
16
17
class Preview implements ApiResponse
18
{
19
    /**
20
     * @var string|null
21
     */
22
    private $id;
23
24
    /**
25
     * @var bool
26
     */
27
    private $valid;
28
29
    /**
30
     * @var string|null
31
     */
32
    private $status;
33
34
    /**
35
     * @var int
36
     */
37
    private $quantity = 0;
38
39
    /**
40
     * @var DateTimeImmutable|null
41
     */
42
    private $createdAt;
43
44
    /**
45
     * @var Summary|null
46
     */
47
    private $summary;
48
49 3
    final private function __construct()
50
    {
51 3
    }
52
53 3
    public static function create(array $data): self
54
    {
55 3
        $model = new static();
56
57 3
        $model->id = $data['id'] ?? null;
58 3
        $model->valid = $data['valid'] ?? null;
59 3
        $model->status = $data['status'] ?? null;
60 3
        $model->quantity = $data['quantity'] ?? null;
61 3
        $model->createdAt = isset($data['created_at']) ? (DateTimeImmutable::createFromFormat('U', (string) ($data['created_at'])) ?: null) : null;
62 3
        $model->summary = $data['summary'] ? Summary::create($data['summary']) : null;
0 ignored issues
show
Documentation Bug introduced by
It seems like $data['summary'] ? \Mail...data['summary']) : null can also be of type object<self>. However, the property $summary is declared as type object<Mailgun\Model\Ema...idationV4\Summary>|null. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
63
64 3
        return $model;
65
    }
66
67 1
    public function getId(): ?string
68
    {
69 1
        return $this->id;
70
    }
71
72 1
    public function isValid(): ?bool
73
    {
74 1
        return $this->valid;
75
    }
76
77 1
    public function getQuantity(): int
78
    {
79 1
        return $this->quantity;
80
    }
81
82 1
    public function getStatus(): ?string
83
    {
84 1
        return $this->status;
85
    }
86
87 1
    public function getCreatedAt(): ?DateTimeImmutable
88
    {
89 1
        return $this->createdAt;
90
    }
91
92 1
    public function getSummary(): ?Summary
93
    {
94 1
        return $this->summary;
95
    }
96
}
97