Completed
Push — components-poc ( 6ce8f4...e1010e )
by
unknown
13:39
created

Folders::remove()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 1
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
    public function add($name, $path, $fallback = false)
26
    {
27
        if ($this->exists($name)) {
28
            throw new LogicException('The template folder "' . $name . '" is already being used.');
29
        }
30
31
        $this->folders[$name] = new Folder($name, $path, $fallback);
32
33
        return $this;
34
    }
35
36
    /**
37
     * Remove a template folder.
38
     * @param  string  $name
39
     * @return Folders
40
     */
41
    public function remove($name)
42
    {
43
        if (!$this->exists($name)) {
44
            throw new LogicException('The template folder "' . $name . '" was not found.');
45
        }
46
47
        unset($this->folders[$name]);
48
49
        return $this;
50
    }
51
52
    /**
53
     * Get a template folder.
54
     * @param  string $name
55
     * @return Folder
56
     */
57
    public function get($name)
58
    {
59
        if (!$this->exists($name)) {
60
            throw new LogicException('The template folder "' . $name . '" was not found.');
61
        }
62
63
        return $this->folders[$name];
64
    }
65
66
    /**
67
     * Check if a template folder exists.
68
     * @param  string  $name
69
     * @return boolean
70
     */
71
    public function exists($name)
72
    {
73
        return isset($this->folders[$name]);
74
    }
75
}
76