Certificate::created()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Importance

Changes 0
Metric Value
dl 4
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php declare(strict_types = 1);
2
3
namespace Link0\Bunq\Domain;
4
5
use DateTimeImmutable;
6
use DateTimeInterface;
7
use DateTimeZone;
8
9 View Code Duplication
final class Certificate
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
10
{
11
    /**
12
     * @var Id
13
     */
14
    private $id;
15
16
    /**
17
     * @var DateTimeInterface
18
     */
19
    private $created;
20
21
    /**
22
     * @var DateTimeInterface
23
     */
24
    private $updated;
25
26
    /**
27
     * @var string
28
     */
29
    private $certificate;
30
31
    /**
32
     * @string
33
     */
34
    private function __construct(string $certificate)
35
    {
36
        $this->certificate = $certificate;
37
    }
38
39
    /**
40
     * @param string $certificate
41
     * @return Certificate
42
     */
43
    public static function fromString(string $certificate)
44
    {
45
        return new self($certificate);
46
    }
47
48
    /**
49
     * @param array $value
50
     * @return Certificate
51
     */
52
    public static function fromArray($value)
53
    {
54
        $timezone = new DateTimeZone('UTC');
55
        $cert = new Certificate($value['certificate_chain']);
56
        $cert->id = Id::fromInteger(intval($value['id']));
57
        $cert->created = new DateTimeImmutable($value['created'], $timezone);
58
        $cert->updated = new DateTimeImmutable($value['updated'], $timezone);
59
        return $cert;
60
    }
61
62
    /**
63
     * @return Id
64
     */
65
    public function id(): Id
66
    {
67
        return $this->id;
68
    }
69
70
    /**
71
     * @return DateTimeInterface
72
     */
73
    public function created(): DateTimeInterface
74
    {
75
        return $this->created;
76
    }
77
78
    /**
79
     * @return DateTimeInterface
80
     */
81
    public function updated(): DateTimeInterface
82
    {
83
        return $this->updated;
84
    }
85
86
    /**
87
     * @return string
88
     */
89
    public function certificate(): string
90
    {
91
        return $this->certificate;
92
    }
93
94
    /**
95
     * @return string
96
     */
97
    public function __toString()
98
    {
99
        return $this->certificate;
100
    }
101
}
102