Attempt.php 1.84 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?php


namespace Source\Entities;

use Carbon\Carbon;

class Attempt
{
    /**
     * @var int
     */
    protected int $id;

    /**
     * @var int
     */
18
    protected int $doorId;
19
20
21
22
23
24
25
26
27
28
29
30
31

    /**
     * @var \Carbon\Carbon|null
     */
    protected ?Carbon $createdAt;

    /**
     * @var \Carbon\Carbon|null
     */
    protected ?Carbon $updatedAt;

    public function __construct(
        int $id,
32
        int $doorId,
33
34
35
36
        ?Carbon $createdAt = null,
        ?Carbon $updatedAt = null
    ) {
        $this->id = $id;
37
        $this->doorId = $doorId;
38
39
40
41
42
43
44
45
46
47
48
49
50
        $this->createdAt = $createdAt;
        $this->updatedAt = $updatedAt;
    }

    /**
     * @return int
     */
    public function getId(): int
    {
        return $this->id;
    }

    /**
51
     * @return int
52
     */
53
    public function getDoorId(): int
54
    {
55
        return $this->doorId;
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
    }

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

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

    /**
     * @param \Carbon\Carbon $begin
     * @param \Carbon\Carbon $end
     * @return bool
     */
Jacob Priddy's avatar
Jacob Priddy committed
79
    public function isBetween(?Carbon $begin, ?Carbon $end): bool
80
    {
Jacob Priddy's avatar
Jacob Priddy committed
81
82
83
84
85
86
87
88
89
90
91
92
93
        if ($begin && $end) {
            return $this->createdAt->isBetween($begin, $end);
        }

        if ($begin) {
            return $this->createdAt->greaterThan($begin);
        }

        if ($end) {
            return $this->createdAt->lessThan($end);
        }

        return true;
94
95
96
    }

    /**
97
     * @param string|null $doorId
98
99
     * @return bool
     */
100
    public function hasDoorIdOf(?string $doorId): bool
101
    {
102
        if (!$doorId) {
103
104
105
            return false;
        }

106
        return $this->getDoorId() === (int)$doorId;
107
108
    }
}