Completed
Pull Request — master (#153)
by Harry
02:35
created

Directory::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1.0156

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 3
cts 4
cp 0.75
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1.0156
1
<?php
2
3
namespace League\Plates\Template;
4
5
use LogicException;
6
7
/**
8
 * Default template directory.
9
 */
10
class Directory
11
{
12
    /**
13
     * Template directory path.
14
     * @var string
15
     */
16
    protected $path;
17
18
    /**
19
     * Create new Directory instance.
20
     * @param string $path
21
     */
22 168
    public function __construct($path = null)
23
    {
24 168
        $this->set($path);
25 168
    }
26
27
    /**
28
     * Set path to templates directory.
29
     * @param  string|null $path Pass null to disable the default directory.
30
     * @return Directory
31
     */
32 168
    public function set($path)
33
    {
34 168
        if (!is_null($path) and !is_dir($path)) {
35 4
            throw new LogicException(
36 4
                'The specified path "' . $path . '" does not exist.'
37 4
            );
38
        }
39
40 168
        $this->path = $path;
41
42 168
        return $this;
43
    }
44
45
    /**
46
     * Get path to templates directory.
47
     * @return string
48
     */
49 82
    public function get()
50
    {
51 82
        return $this->path;
52
    }
53
}
54