Lock::key()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of the LockerManager package.
4
 *
5
 * (c) Mauro Cassani<https://github.com/mauretto78>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace LockerManager\Domain;
12
13
use Cocur\Slugify\Slugify;
14
use Ramsey\Uuid\Uuid;
15
16
class Lock
17
{
18
    /**
19
     * @var \Ramsey\Uuid\UuidInterface
20
     */
21
    private $id;
22
23
    /**
24
     * @var string
25
     */
26
    private $key;
27
28
    /**
29
     * @var
30
     */
31
    private $payload;
32
33
    /**
34
     * @var \DateTime
35
     */
36
    private $created_at;
37
38
    /**
39
     * @var \DateTime
40
     */
41
    private $modified_at;
42
43
    /**
44
     * Lock constructor.
45
     * @param $key
46
     * @param $payload
47
     */
48
    public function __construct(
49
        $key,
50
        $payload
51
    ) {
52
        $this->id = Uuid::uuid4();
53
        $this->key = $key;
54
        $this->payload = $payload;
55
        $this->created_at = new \DateTime();
56
        $this->modified_at = new \DateTime();
57
    }
58
59
    /**
60
     * @return \Ramsey\Uuid\UuidInterface
61
     */
62
    public function id()
63
    {
64
        return $this->id;
65
    }
66
67
    /**
68
     * @return string
69
     */
70
    public function key()
71
    {
72
        return (new Slugify())->slugify($this->key);
73
    }
74
75
    /**
76
     * @return mixed
77
     */
78
    public function payload()
79
    {
80
        return $this->payload;
81
    }
82
83
    /**
84
     * @return \DateTime
85
     */
86
    public function createdAt()
87
    {
88
        return $this->created_at;
89
    }
90
91
    /**
92
     * @return \DateTime
93
     */
94
    public function modifiedAt()
95
    {
96
        return $this->modified_at;
97
    }
98
99
    public function update($payload)
100
    {
101
        $this->payload = $payload;
102
        $this->modified_at = new \DateTime();
103
    }
104
}
105