InotifyWatchRecord::isDirectory()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace App\Libraries\WatchRecord;
4
5
class InotifyWatchRecord extends WatchRecord implements WatchRecordInterface
6
{
7
    /**
8
     * {@inheritdoc}
9
     *
10
     * @param string $input
11
     */
12 3
    public function __construct(string $input)
13
    {
14 3
        parent::__construct($input);
15 3
        $this->parse($input);
16 3
    }
17
18
    /**
19
     * Parse the inotifywait's output. The inotifywait command should be something like:
20
     * $ inotifywait -rme move,close_write,delete --format "%e %w%f" $MEDIA_PATH.
21
     */
22 3
    public function parse(string $string): void
23
    {
24 3
        list($events, $this->path) = explode(' ', $string, 2);
25 3
        $this->events = explode(',', $events);
26 3
    }
27
28
    /**
29
     * Determine if the object has just been deleted or moved from our watched directory.
30
     */
31 3
    public function isDeleted(): bool
32
    {
33 3
        return $this->eventExists('DELETE') || $this->eventExists('MOVED_FROM');
34
    }
35
36
    /**
37
     * Determine if the object has just been created or modified.
38
     * For our purpose, we watch both the CREATE and the CLOSE_WRITE event, because some operating
39
     * systems only support CREATE, but not CLOSE_WRITE and MOVED_TO.
40
     * Additionally, a MOVED_TO (occurred after the object has been moved/renamed to another location
41
     * **under our watched directory**) should be considered as "modified" also.
42
     */
43 1
    public function isNewOrModified(): bool
44
    {
45 1
        return $this->eventExists('CLOSE_WRITE') || $this->eventExists('CREATE') || $this->eventExists('MOVED_TO');
46
    }
47
48 3
    public function isDirectory(): bool
49
    {
50 3
        return $this->eventExists('ISDIR');
51
    }
52
}
53