ArrayTemplate   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 98
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 98
rs 10
c 0
b 0
f 0
wmc 9
lcom 0
cbo 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 3
A getDefaultTemplate() 0 4 1
A setDefaultTemplate() 0 6 1
A getNegatedTemplate() 0 4 1
A setNegatedTemplate() 0 6 1
A getTemplateVars() 0 4 1
A setTemplateVars() 0 6 1
1
<?php
2
3
namespace Peridot\Leo\Matcher\Template;
4
5
/**
6
 * ArrayTemplate uses an array to specify default and negated templates. An ArrayTemplate is constructed
7
 * with array keys.
8
 *
9
 * @code
10
 * $template = new ArrayTemplate([
11
 *     'default' => "Expected {{actual}} to be {{expected}}",
12
 *     'negated' => "Expected {{actual}} not to be {{expected}}
13
 * ]);
14
 * @endcode
15
 *
16
 * @package Peridot\Leo\Matcher\Template
17
 */
18
class ArrayTemplate implements TemplateInterface
19
{
20
    /**
21
     * @var string
22
     */
23
    protected $default = '';
24
25
    /**
26
     * @var string
27
     */
28
    protected $negated = '';
29
30
    /**
31
     * @var array
32
     */
33
    protected $vars = [];
34
35
    /**
36
     * @param array $templates
37
     */
38
    public function __construct(array $templates)
39
    {
40
        if (array_key_exists('default', $templates)) {
41
            $this->default = $templates['default'];
42
        }
43
44
        if (array_key_exists('negated', $templates)) {
45
            $this->negated = $templates['negated'];
46
        }
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     *
52
     * @return string
53
     */
54
    public function getDefaultTemplate()
55
    {
56
        return $this->default;
57
    }
58
59
    /**
60
     * {@inheritdoc}
61
     *
62
     * @param string $default
63
     */
64
    public function setDefaultTemplate($default)
65
    {
66
        $this->default = $default;
67
68
        return $this;
69
    }
70
71
    /**
72
     * {@inheritdoc}
73
     *
74
     * @return string
75
     */
76
    public function getNegatedTemplate()
77
    {
78
        return $this->negated;
79
    }
80
81
    /**
82
     * {@inheritdoc}
83
     *
84
     * @param string $negated
85
     */
86
    public function setNegatedTemplate($negated)
87
    {
88
        $this->negated = $negated;
89
90
        return $this;
91
    }
92
93
    /**
94
     * {@inheritdoc}
95
     *
96
     * @return array
97
     */
98
    public function getTemplateVars()
99
    {
100
        return $this->vars;
101
    }
102
103
    /**
104
     * {@inheritdoc}
105
     *
106
     * @param  array $vars
107
     * @return $this
108
     */
109
    public function setTemplateVars(array $vars)
110
    {
111
        $this->vars = $vars;
112
113
        return $this;
114
    }
115
}
116