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

Status   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
c 0
b 0
f 0
lcom 0
cbo 1
dl 0
loc 50
ccs 0
cts 17
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 1
A createFromArray() 0 14 1
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