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

Job::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
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 Job implements ApiResponse
18
{
19
    /**
20
     * @var DateTimeImmutable|null
21
     */
22
    private $createdAt;
23
24
    /**
25
     * @var JobDownloadUrl|null
26
     */
27
    private $downloadUrl;
28
29
    /**
30
     * @var string|null
31
     */
32
    private $id;
33
34
    /**
35
     * @var int
36
     */
37
    private $quantity = 0;
38
39
    /**
40
     * @var int
41
     */
42
    private $recordsProcessed = 0;
43
44
    /**
45
     * @var string|null
46
     */
47
    private $status;
48
49
    /**
50
     * @var Summary|null
51
     */
52
    private $summary;
53
54 3
    final private function __construct()
55
    {
56 3
    }
57
58 3
    public static function create(array $data): self
59
    {
60 3
        $model = new static();
61
62 3
        $model->createdAt = isset($data['created_at']) ? (DateTimeImmutable::createFromFormat('U', (string) ($data['created_at'])) ?: null) : null;
63 3
        $model->downloadUrl = $data['download_url'] ? JobDownloadUrl::create($data['download_url']) : null;
0 ignored issues
show
Documentation Bug introduced by
It seems like $data['download_url'] ? ...'download_url']) : null can also be of type object<self>. However, the property $downloadUrl is declared as type object<Mailgun\Model\Ema...V4\JobDownloadUrl>|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...
64 3
        $model->id = $data['id'] ?? null;
65 3
        $model->quantity = $data['quantity'] ?? null;
66 3
        $model->recordsProcessed = $data['records_processed'] ?? null;
67 3
        $model->status = $data['status'] ?? null;
68 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...
69
70 3
        return $model;
71
    }
72
73 2
    public function getCreatedAt(): ?DateTimeImmutable
74
    {
75 2
        return $this->createdAt;
76
    }
77
78 2
    public function getDownloadUrl(): ?JobDownloadUrl
79
    {
80 2
        return $this->downloadUrl;
81
    }
82
83 2
    public function getId(): ?string
84
    {
85 2
        return $this->id;
86
    }
87
88 2
    public function getQuantity(): int
89
    {
90 2
        return $this->quantity;
91
    }
92
93 2
    public function getRecordsProcessed(): int
94
    {
95 2
        return $this->recordsProcessed;
96
    }
97
98 2
    public function getStatus(): ?string
99
    {
100 2
        return $this->status;
101
    }
102
103 2
    public function getSummary(): ?Summary
104
    {
105 2
        return $this->summary;
106
    }
107
}
108