Functions   A
last analyzed

Coupling/Cohesion

Components 1
Dependencies 1

Complexity

Total Complexity 7

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Test Coverage

Coverage 64.52%

Importance

Changes 0
Metric Value
wmc 7
c 0
b 0
f 0
lcom 1
cbo 1
dl 0
loc 69
ccs 20
cts 31
cp 0.6452
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A add() 0 12 2
A remove() 0 12 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 functions.
9
 */
10
class Functions
11
{
12
    /**
13
     * Array of template functions.
14
     * @var array
15
     */
16
    protected $functions = array();
17
18
    /**
19
     * Add a new template function.
20
     * @param  string    $name;
21
     * @param  callback  $callback;
22
     * @return Functions
23
     */
24 86
    public function add($name, $callback)
25
    {
26 86
        if ($this->exists($name)) {
27 2
            throw new LogicException(
28 2
                'The template function name "' . $name . '" is already registered.'
29 2
            );
30
        }
31
32 86
        $this->functions[$name] = new Func($name, $callback);
33
34 86
        return $this;
35
    }
36
37
    /**
38
     * Remove a template function.
39
     * @param  string    $name;
40
     * @return Functions
41
     */
42 8
    public function remove($name)
43
    {
44 8
        if (!$this->exists($name)) {
45 4
            throw new LogicException(
46 4
                'The template function "' . $name . '" was not found.'
47 4
            );
48
        }
49
50 4
        unset($this->functions[$name]);
51
52 4
        return $this;
53
    }
54
55
    /**
56
     * Get a template function.
57
     * @param  string $name
58
     * @return Func
59
     */
60 14
    public function get($name)
61
    {
62 14
        if (!$this->exists($name)) {
63 4
            throw new LogicException('The template function "' . $name . '" was not found.');
64
        }
65
66 10
        return $this->functions[$name];
67
    }
68
69
    /**
70
     * Check if a template function exists.
71
     * @param  string  $name
72
     * @return boolean
73
     */
74 96
    public function exists($name)
75
    {
76 96
        return isset($this->functions[$name]);
77
    }
78
}
79