Completed
Push — master ( 43d6c5...49981b )
by Yuri
02:20
created

BaseTemplate::setPrefix()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1.064

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 6
ccs 3
cts 5
cp 0.6
crap 1.064
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Tamtamchik\SimpleFlash;
4
5
use Tamtamchik\SimpleFlash\Exceptions\FlashTemplateException;
6
7
/**
8
 * Class BaseTemplate.
9
 *
10
 * @property string prefix  - line prefix
11
 * @property string postfix - line postfix
12
 * @property string wrapper - flash wrapper
13
 */
14
abstract class BaseTemplate implements TemplateInterface
15
{
16
    /**
17
     * @param string $messages - message text
18
     * @param string $type - message type: success, info, warning, error
19
     *
20
     * @return string
21
     */
22
    abstract public function wrapMessages($messages, $type);
23
24
    /**
25
     * @param $message - message text
26
     *
27
     * @return string
28
     */
29 42
    public function wrapMessage($message)
30
    {
31 42
        return $this->getPrefix() . $message . $this->getPostfix();
32
    }
33
34
    /**
35
     * @return string
36
     */
37 42
    public function getPrefix()
38
    {
39 42
        return $this->prefix;
40
    }
41
42
    /**
43
     * @param string $prefix
44
     *
45
     * @return TemplateInterface $this
46
     */
47 4
    public function setPrefix($prefix)
48
    {
49 4
        $this->prefix = $prefix;
50
51 4
        return $this;
52
    }
53
54
    /**
55
     * @return string
56
     */
57 40
    public function getPostfix()
58
    {
59 40
        return $this->postfix;
60
    }
61
62
    /**
63
     * @param string $postfix
64
     *
65
     * @return TemplateInterface $this
66
     */
67 4
    public function setPostfix($postfix)
68
    {
69 4
        $this->postfix = $postfix;
70
71 4
        return $this;
72
    }
73
74
    /**
75
     * @return string
76
     */
77 40
    public function getWrapper()
78
    {
79 40
        return $this->wrapper;
80
    }
81
82
    /**
83
     * @param string $wrapper
84
     *
85
     * @return TemplateInterface $this
86
     */
87 2
    public function setWrapper($wrapper)
88
    {
89 2
        $this->wrapper = $wrapper;
90
91 2
        return $this;
92
    }
93
94
    /**
95
     * Check that you have all fields defined in template and throw an exception if not.
96
     *
97
     * @param $name
98
     *
99
     * @throws FlashTemplateException
100
     */
101 2
    public function __get($name)
102
    {
103 2
        throw new FlashTemplateException("No \"{$name}\" defined in template! Please, make sure you have prefix, postfix and wrapper defined!");
104
    }
105
}
106