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

Directory::set()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3.243

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 12
ccs 7
cts 10
cp 0.7
rs 9.4285
cc 3
eloc 6
nc 2
nop 1
crap 3.243
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