Folders   A
last analyzed

↳ Parent: Project

Coupling/Cohesion

Components 1
Dependencies 1

Complexity

Total Complexity 7

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 66
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

4 Methods

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