InotifyWatchRecord   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
eloc 8
c 0
b 0
f 0
dl 0
loc 46
ccs 14
cts 14
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A isDeleted() 0 3 2
A isDirectory() 0 3 1
A isNewOrModified() 0 3 3
A parse() 0 4 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