Message::error()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
namespace WagnerMontanini\GoomerApi\Support;
4
5
use WagnerMontanini\GoomerApi\Core\Session;
0 ignored issues
show
Bug introduced by
The type WagnerMontanini\GoomerApi\Core\Session was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
7
/**
8
 * Class Message
9
 *
10
 * @author Wagner Montanini
11
 * @package WagnerMontanini\GoomerApi\Core
12
 */
13
class Message
14
{
15
    /** @var string */
16
    private $text;
17
18
    /** @var string */
19
    private $type;
20
21
    /** @var string */
22
    private $before;
23
24
    /** @var string */
25
    private $after;
26
27
    /**
28
     * @return string
29
     */
30
    public function __toString()
31
    {
32
        return $this->render();
33
    }
34
35
    /**
36
     * @return string
37
     */
38
    public function getText(): ?string
39
    {
40
        return $this->before . $this->text . $this->after;
41
    }
42
43
    /**
44
     * @return string
45
     */
46
    public function getType(): ?string
47
    {
48
        return $this->type;
49
    }
50
51
    /**
52
     * @param string $text
53
     * @return Message
54
     */
55
    public function before(string $text): Message
56
    {
57
        $this->before = $text;
58
        return $this;
59
    }
60
61
    /**
62
     * @param string $text
63
     * @return Message
64
     */
65
    public function after(string $text): Message
66
    {
67
        $this->after = $text;
68
        return $this;
69
    }
70
71
    /**
72
     * @param string $message
73
     * @return Message
74
     */
75
    public function info(string $message): Message
76
    {
77
        $this->type = "info icon-info";
78
        $this->text = $this->filter($message);
79
        return $this;
80
    }
81
82
    /**
83
     * @param string $message
84
     * @return Message
85
     */
86
    public function success(string $message): Message
87
    {
88
        $this->type = "success icon-check-square-o";
89
        $this->text = $this->filter($message);
90
        return $this;
91
    }
92
93
    /**
94
     * @param string $message
95
     * @return Message
96
     */
97
    public function warning(string $message): Message
98
    {
99
        $this->type = "warning icon-warning";
100
        $this->text = $this->filter($message);
101
        return $this;
102
    }
103
104
    /**
105
     * @param string $message
106
     * @return Message
107
     */
108
    public function error(string $message): Message
109
    {
110
        $this->type = "error icon-warning";
111
        $this->text = $this->filter($message);
112
        return $this;
113
    }
114
115
    /**
116
     * @return string
117
     */
118
    public function render(): string
119
    {
120
        return "<div class='message {$this->getType()}'>{$this->getText()}</div>";
121
    }
122
123
    /**
124
     * Set flash Session Key
125
     */
126
    public function flash(): void
127
    {
128
        (new Session())->set("flash", $this);
129
    }
130
131
    /**
132
     * @param string $message
133
     * @return string
134
     */
135
    private function filter(string $message): string
136
    {
137
        return filter_var($message, FILTER_SANITIZE_STRIPPED);
138
    }
139
}