Token   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 77
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 77
loc 77
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A fromArray() 10 10 1
A id() 4 4 1
A created() 4 4 1
A updated() 4 4 1
A token() 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 Token
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 $token;
30
31
    /**
32
     * @param array $token
33
     * @return Token
34
     */
35
    public static function fromArray(array $token)
36
    {
37
        $timezone = new DateTimeZone('UTC');
38
        $t = new Token();
39
        $t->id = Id::fromInteger(intval($token['id']));
40
        $t->created = new DateTimeImmutable($token['created'], $timezone);
41
        $t->updated = new DateTimeImmutable($token['updated'], $timezone);
42
        $t->token = $token['token'];
43
        return $t;
44
    }
45
46
    /**
47
     * @return Id
48
     */
49
    public function id(): Id
50
    {
51
        return $this->id;
52
    }
53
54
    /**
55
     * @return DateTimeInterface
56
     */
57
    public function created(): DateTimeInterface
58
    {
59
        return $this->created;
60
    }
61
62
    /**
63
     * @return DateTimeInterface
64
     */
65
    public function updated(): DateTimeInterface
66
    {
67
        return $this->updated;
68
    }
69
70
    /**
71
     * @return string
72
     */
73
    public function token(): string
0 ignored issues
show
Coding Style Best Practice introduced by
Please use __construct() instead of a PHP4-style constructor that is named after the class.
Loading history...
74
    {
75
        return $this->token;
76
    }
77
78
    /**
79
     * @return string
80
     */
81
    public function __toString()
82
    {
83
        return $this->token();
84
    }
85
}
86