Completed
Push — master ( cb7793...7b1e0a )
by Arne
01:36
created

Synchronization   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 1
dl 0
loc 87
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A getRevision() 0 4 1
A getTime() 0 4 1
A getIdentity() 0 4 1
A getBlobId() 0 4 1
A getRecord() 0 9 1
A fromRecord() 0 14 3
1
<?php
2
3
namespace Archivr;
4
5
use Archivr\Exception\Exception;
6
7
class Synchronization
8
{
9
    /**
10
     * @var int
11
     */
12
    protected $revision;
13
14
    /**
15
     * @var \DateTime
16
     */
17
    protected $time;
18
19
    /**
20
     * @var string
21
     */
22
    protected $identity;
23
24
    /**
25
     * @var string
26
     */
27
    protected $blobId;
28
29
    public function __construct(int $revision, string $blobId, \DateTime $time, string $identity = null)
30
    {
31
        $this->revision = $revision;
32
        $this->blobId = $blobId;
33
        $this->time = $time;
34
        $this->identity = $identity;
35
    }
36
37
    /**
38
     * @return int
39
     */
40
    public function getRevision(): int
41
    {
42
        return $this->revision;
43
    }
44
45
    /**
46
     * @return \DateTime
47
     */
48
    public function getTime(): \DateTime
49
    {
50
        return $this->time;
51
    }
52
53
    /**
54
     * @return string
55
     */
56
    public function getIdentity()
57
    {
58
        return $this->identity;
59
    }
60
61
    /**
62
     * @return string
63
     */
64
    public function getBlobId(): string
65
    {
66
        return $this->blobId;
67
    }
68
69
    public function getRecord(): array
70
    {
71
        return [
72
            $this->revision,
73
            $this->blobId,
74
            $this->time->getTimestamp(),
75
            $this->identity
76
        ];
77
    }
78
79
    public static function fromRecord(array $row): Synchronization
80
    {
81
        $revision = $row[0];
82
        $blobId = $row[1];
83
        $time = \DateTime::createFromFormat('U', $row[2]);
84
        $identity = $row[3] ?: null;
85
86
        if (!($time instanceof \DateTime))
87
        {
88
            throw new Exception();
89
        }
90
91
        return new static($revision, $blobId, $time, $identity);
92
    }
93
}
94