BaseTemplate::setPrefix()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 10
c 1
b 0
f 1
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(string $messages, string $type): string;
23
24
    /**
25
     * @param string $message - message text
26
     *
27
     * @return string
28
     */
29 42
    public function wrapMessage(string $message): string
30
    {
31 42
        return $this->getPrefix() . $message . $this->getPostfix();
32
    }
33
34
    /**
35
     * @return string
36
     */
37 42
    public function getPrefix(): string
38
    {
39 42
        return $this->prefix;
40
    }
41
42
    /**
43
     * @return string
44
     */
45 41
    public function getPostfix(): string
46
    {
47 41
        return $this->postfix;
48
    }
49
50
    /**
51
     * @param string $prefix
52
     *
53
     * @return TemplateInterface $this
54
     */
55 2
    public function setPrefix(string $prefix): TemplateInterface
56
    {
57 2
        $this->prefix = $prefix;
58
59 2
        return $this;
60
    }
61
62
    /**
63
     * @param string $postfix
64
     *
65
     * @return TemplateInterface $this
66
     */
67 2
    public function setPostfix(string $postfix): TemplateInterface
68
    {
69 2
        $this->postfix = $postfix;
70
71 2
        return $this;
72
    }
73
74
    /**
75
     * @return string
76
     */
77 41
    public function getWrapper(): string
78
    {
79 41
        return $this->wrapper;
80
    }
81
82
    /**
83
     * @param string $wrapper
84
     *
85
     * @return TemplateInterface $this
86
     */
87 1
    public function setWrapper(string $wrapper): TemplateInterface
88
    {
89 1
        $this->wrapper = $wrapper;
90
91 1
        return $this;
92
    }
93
94
    /**
95
     * Check that you have all fields defined in template and throw an exception if not.
96
     *
97
     * @param string $name
98
     *
99
     * @throws FlashTemplateException
100
     */
101 1
    public function __get(string $name): void
102
    {
103 1
        throw new FlashTemplateException("No \"$name\" defined in template! Please, make sure you have prefix, postfix and wrapper defined!");
104
    }
105
}
106