Completed
Pull Request — master (#21)
by Erin
09:47
created

ArrayTemplate   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 95
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 4
Bugs 0 Features 3
Metric Value
wmc 9
c 4
b 0
f 3
lcom 0
cbo 0
dl 0
loc 95
rs 10

7 Methods

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