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

Folders::remove()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2.2109

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 10
ccs 5
cts 8
cp 0.625
rs 9.4285
cc 2
eloc 5
nc 2
nop 1
crap 2.2109
1
<?php
2
3
namespace League\Plates\Template;
4
5
use LogicException;
6
7
/**
8
 * A collection of template folders.
9
 */
10
class Folders
11
{
12
    /**
13
     * Array of template folders.
14
     * @var array
15
     */
16
    protected $folders = array();
17
18
    /**
19
     * Add a template folder.
20
     * @param  string  $name
21
     * @param  string  $path
22
     * @param  boolean $fallback
23
     * @return Folders
24
     */
25 54
    public function add($name, $path, $fallback = false)
26
    {
27 54
        if ($this->exists($name)) {
28 4
            throw new LogicException('The template folder "' . $name . '" is already being used.');
29
        }
30
31 54
        $this->folders[$name] = new Folder($name, $path, $fallback);
32
33 50
        return $this;
34
    }
35
36
    /**
37
     * Remove a template folder.
38
     * @param  string  $name
39
     * @return Folders
40
     */
41 6
    public function remove($name)
42
    {
43 6
        if (!$this->exists($name)) {
44 2
            throw new LogicException('The template folder "' . $name . '" was not found.');
45
        }
46
47 4
        unset($this->folders[$name]);
48
49 4
        return $this;
50
    }
51
52
    /**
53
     * Get a template folder.
54
     * @param  string $name
55
     * @return Folder
56
     */
57 18
    public function get($name)
58
    {
59 18
        if (!$this->exists($name)) {
60 2
            throw new LogicException('The template folder "' . $name . '" was not found.');
61
        }
62
63 16
        return $this->folders[$name];
64
    }
65
66
    /**
67
     * Check if a template folder exists.
68
     * @param  string  $name
69
     * @return boolean
70
     */
71 58
    public function exists($name)
72
    {
73 58
        return isset($this->folders[$name]);
74
    }
75
}
76