Completed
Push — master ( 6a6e14...e9047f )
by Julián
02:21
created

File::addFile()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
/**
3
 * Effortless maintenance management (http://juliangut.com/janitor)
4
 *
5
 * @link https://github.com/juliangut/janitor for the canonical source repository
6
 *
7
 * @license https://github.com/juliangut/janitor/blob/master/LICENSE
8
 */
9
10
namespace Janitor\Watcher;
11
12
use Janitor\Watcher as WatcherInterface;
13
14
/**
15
 * File existance check for maintenance status watcher.
16
 */
17
class File implements WatcherInterface
18
{
19
    /**
20
     * File path.
21
     *
22
     * @var string
23
     */
24
    protected $file;
25
26
    /**
27
     * @param string|array|null $files
28
     */
29
    public function __construct($files = null)
30
    {
31
        if (!is_array($files)) {
32
            $files = [$files];
33
        }
34
35
        foreach ($files as $file) {
36
            $this->addFile($file);
37
        }
38
    }
39
40
    /**
41
     * Add file path.
42
     *
43
     * @param string $file
44
     *
45
     * @return $this
46
     */
47
    public function addFile($file)
48
    {
49
        if (trim($file) !== '') {
50
            $this->file = realpath(trim($file));
51
        }
52
53
        return $this;
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59
    public function isActive()
60
    {
61
        return file_exists($this->file) && is_file($this->file);
62
    }
63
}
64