Issues (87)

src/HotReload/FSEvent.php (1 issue)

1
<?php
2
3
namespace SwooleTW\Http\HotReload;
4
5
use Illuminate\Support\Arr;
6
use Carbon\Carbon;
7
8
/**
9
 * Class FSEvent
10
 */
11
class FSEvent
12
{
13
    /**
14
     * Event - Created.
15
     *
16
     * @var string
17
     */
18
    public const Created = 'Created';
19
20
    /**
21
     * Event - Updated.
22
     *
23
     * @var string
24
     */
25
    public const Updated = 'Updated';
26
27
    /**
28
     * Event - Removed.
29
     *
30
     * @var string
31
     */
32
    public const Removed = 'Removed';
33
34
    /**
35
     * Event - Renamed.
36
     *
37
     * @var string
38
     */
39
    public const Renamed = 'Renamed';
40
41
    /**
42
     * Event - OwnerModified.
43
     *
44
     * @var string
45
     */
46
    public const OwnerModified = 'OwnerModified';
47
48
    /**
49
     * Event - AttributeModified.
50
     *
51
     * @var string
52
     */
53
    public const AttributeModified = 'AttributeModified';
54
55
    /**
56
     * Event - MovedFrom.
57
     *
58
     * @var string
59
     */
60
    public const MovedFrom = 'MovedFrom';
61
62
    /**
63
     * Event - MovedTo.
64
     *
65
     * @var string
66
     */
67
    public const MovedTo = 'MovedTo';
68
69
    /**
70
     * Possible event types.
71
     *
72
     * @var array
73
     */
74
    protected static $possibleTypes = [
75
        self::Created, self::Updated, self::Removed, self::Renamed,
76
        self::OwnerModified, self::AttributeModified, self::MovedFrom, self::MovedTo,
77
    ];
78
79
    /**
80
     * When event fired.
81
     *
82
     * @var \Carbon\Carbon
83
     */
84
    protected $when;
85
86
    /**
87
     * Directory or file path.
88
     *
89
     * @var string
90
     */
91
    protected $path;
92
93
    /**
94
     * Event types.
95
     *
96
     * @var array
97
     */
98
    protected $types;
99
100
    /**
101
     * Event constructor.
102
     *
103
     * @param \Carbon\Carbon $when
104
     * @param string $path
105
     * @param array $types
106
     */
107
    public function __construct(Carbon $when, string $path, array $types)
108
    {
109
        $this->when = $when;
110
        $this->path = $path;
111
        $this->types = $types;
112
    }
113
114
    /**
115
     * @return \Carbon\Carbon
116
     */
117
    public function getWhen(): Carbon
118
    {
119
        return $this->when;
120
    }
121
122
    /**
123
     * @return string
124
     */
125
    public function getPath(): string
126
    {
127
        return $this->path;
128
    }
129
130
    /**
131
     * @return array
132
     */
133
    public function getTypes(): array
134
    {
135
        return $this->types;
136
    }
137
138
    /**
139
     * @return string
140
     */
141
    public function getType(): string
142
    {
143
        return Arr::first($this->types);
0 ignored issues
show
Bug Best Practice introduced by
The expression return Illuminate\Suppor...rr::first($this->types) could return the type null which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
144
    }
145
146
    /**
147
     * Checks if event types has needed type(s).
148
     *
149
     * @param string ...$types
150
     *
151
     * @return bool
152
     */
153
    public function isType(string ...$types): bool
154
    {
155
        return count(array_intersect($this->types, $types)) > 0;
156
    }
157
158
    /**
159
     * Get possible event types.
160
     *
161
     * @return array
162
     */
163
    public static function getPossibleTypes(): array
164
    {
165
        return self::$possibleTypes;
166
    }
167
}