Door.php 3.22 KB
Newer Older
1
2
3
4
5
6
7
<?php


namespace Source\Entities;

use Carbon\Carbon;

Jacob Priddy's avatar
Jacob Priddy committed
8
9
class Door
{
10
11
12
    /**
     * @var int
     */
13
14
    protected int $id;

15
16
17
    /**
     * @var string
     */
18
19
    protected string $location;

20
21
22
    /**
     * @var string
     */
23
24
    protected string $name;

25
26
27
    /**
     * @var \Source\Entities\HashedSearchable
     */
28
    protected HashedSearchable $token;
29

30
31
32
    /**
     * @var \Carbon\Carbon|null
     */
33
34
    protected ?Carbon $createdAt;

35
36
37
    /**
     * @var \Carbon\Carbon|null
     */
38
39
    protected ?Carbon $updatedAt;

40
41
42
43
44
    /**
     * @var \Carbon\Carbon|null
     */
    protected ?Carbon $lastSeenAt;

45
    /**
46
47
48
49
50
51
     * @param int                               $id
     * @param string                            $location
     * @param string                            $name
     * @param \Source\Entities\HashedSearchable $token
     * @param Carbon|null                       $createdAt
     * @param Carbon|null                       $updatedAt
52
     * @param \Carbon\Carbon|null               $lastSeenAt
53
     */
Jacob Priddy's avatar
Jacob Priddy committed
54
55
56
57
    public function __construct(
        int $id,
        string $location,
        string $name,
58
        HashedSearchable $token,
Jacob Priddy's avatar
Jacob Priddy committed
59
        ?Carbon $createdAt = null,
60
61
        ?Carbon $updatedAt = null,
        ?Carbon $lastSeenAt = null
Jacob Priddy's avatar
Jacob Priddy committed
62
    ) {
63
64
65
66
67
68
        $this->id = $id;
        $this->location = $location;
        $this->name = $name;
        $this->token = $token;
        $this->createdAt = $createdAt;
        $this->updatedAt = $updatedAt;
69
        $this->lastSeenAt = $lastSeenAt;
70
71
72
73
74
    }

    /**
     * @return int
     */
Jacob Priddy's avatar
Jacob Priddy committed
75
76
    public function getId(): int
    {
77
78
79
80
81
82
        return $this->id;
    }

    /**
     * @return string
     */
Jacob Priddy's avatar
Jacob Priddy committed
83
84
    public function getLocation(): string
    {
85
86
87
88
89
90
        return $this->location;
    }

    /**
     * @return string
     */
Jacob Priddy's avatar
Jacob Priddy committed
91
92
    public function getName(): string
    {
93
94
95
96
97
98
        return $this->name;
    }

    /**
     * @return Carbon|null
     */
Jacob Priddy's avatar
Jacob Priddy committed
99
100
    public function getCreatedAt(): ?Carbon
    {
101
102
103
104
105
106
        return $this->createdAt;
    }

    /**
     * @return Carbon|null
     */
Jacob Priddy's avatar
Jacob Priddy committed
107
108
    public function getUpdatedAt(): ?Carbon
    {
109
110
        return $this->updatedAt;
    }
111
112
113
114
115
116
117
118

    /**
     * @return \Carbon\Carbon|null
     */
    public function getLastSeenAt(): ?Carbon
    {
        return $this->lastSeenAt;
    }
119

120
121
122
123
    /**
     * @param \Source\Entities\HashedSearchable|null $token
     * @return bool
     */
124
    public function hasTokenOf(?HashedSearchable $token): bool
Jacob Priddy's avatar
Jacob Priddy committed
125
    {
126
127
128
129
        if (!$token) {
            return false;
        }

130
        return $this->getToken()->getHash() === $token->getHash();
131
    }
Jacob Priddy's avatar
Jacob Priddy committed
132
133

    /**
134
     * @return \Source\Entities\HashedSearchable
Jacob Priddy's avatar
Jacob Priddy committed
135
     */
136
    public function getToken(): HashedSearchable
Jacob Priddy's avatar
Jacob Priddy committed
137
138
139
    {
        return $this->token;
    }
140

141
142
143
144
    /**
     * @param string|null $name
     * @return bool
     */
Jacob Priddy's avatar
Jacob Priddy committed
145
146
147
148
149
150
151
152
153
    public function hasNameOf(?string $name): bool
    {
        if (!$name) {
            return false;
        }

        return $this->name === $name;
    }

154
155
156
157
158
159
160
161
162
163
164
165
    /**
     * @param string $id
     * @return bool
     */
    public function hasIdOf(?string $id): bool
    {
        if (!$id) {
            return false;
        }

        return $this->id === (int)$id;
    }
166
167
168
169

    /**
     * @param string $id
     */
170
    public function setId(int $id): void
171
172
173
    {
        $this->id = $id;
    }
174
}