Completed
Pull Request — master (#5)
by Peter
02:31
created

Status::createFromArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 14
ccs 0
cts 10
cp 0
rs 9.4285
cc 1
eloc 10
nc 1
nop 1
crap 2
1
<?php
2
3
namespace PtrTn\Battlerite\Dto\Status;
4
5
use DateTime;
6
use PtrTn\Battlerite\Assert\Assert;
7
8
class Status
9
{
10
    /**
11
     * @var string
12
     */
13
    public $type;
14
15
    /**
16
     * @var string
17
     */
18
    public $id;
19
20
    /**
21
     * @var DateTime
22
     */
23
    public $releasedAt;
24
25
    /**
26
     * @var string
27
     */
28
    public $version;
29
30
    public function __construct(
31
        string $type,
32
        string $id,
33
        DateTime $releasedAt,
34
        string $version
35
    ) {
36
        $this->type = $type;
37
        $this->type = $type;
38
        $this->id = $id;
39
        $this->releasedAt = $releasedAt;
40
        $this->version = $version;
41
    }
42
43
    public static function createFromArray($status): self
44
    {
45
        Assert::string($status['type']);
46
        Assert::string($status['id']);
47
        Assert::date($status['attributes']['releasedAt'], DateTime::ISO8601);
48
        Assert::string($status['attributes']['version']);
49
50
        return new self(
51
            $status['type'],
52
            $status['id'],
53
            DateTime::createFromFormat(DateTime::ISO8601, $status['attributes']['releasedAt']),
0 ignored issues
show
Security Bug introduced by
It seems like \DateTime::createFromFor...ibutes']['releasedAt']) targeting DateTime::createFromFormat() can also be of type false; however, PtrTn\Battlerite\Dto\Status\Status::__construct() does only seem to accept object<DateTime>, did you maybe forget to handle an error condition?
Loading history...
54
            $status['attributes']['version']
55
        );
56
    }
57
}
58