Completed
Push — master ( e99512...934009 )
by Peter
01:49
created

Status   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

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

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;
4
5
use DateTime;
6
use Webmozart\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 1
    public function __construct(
31
        string $type,
32
        string $id,
33
        DateTime $releasedAt,
34
        string $version
35
    ) {
36 1
        $this->type = $type;
37 1
        $this->type = $type;
38 1
        $this->id = $id;
39 1
        $this->releasedAt = $releasedAt;
40 1
        $this->version = $version;
41 1
    }
42
43 1
    public static function createFromArray($status): self
44
    {
45 1
        Assert::string($status['type']);
46 1
        Assert::string($status['id']);
47 1
        Assert::string($status['attributes']['releasedAt']);
48 1
        Assert::string($status['attributes']['version']);
49
50 1
        return new self(
51 1
            $status['type'],
52 1
            $status['id'],
53 1
            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::__construct() does only seem to accept object<DateTime>, did you maybe forget to handle an error condition?
Loading history...
54 1
            $status['attributes']['version']
55
        );
56
    }
57
}
58