Certificate   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 93
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 1
dl 93
loc 93
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A fromString() 4 4 1
A fromArray() 9 9 1
A id() 4 4 1
A created() 4 4 1
A updated() 4 4 1
A certificate() 4 4 1
A __toString() 4 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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