Passed
Push — 3.0 ( b611c9...572608 )
by Rubén
03:38
created

NotificationMessage   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 20
dl 0
loc 65
rs 10
c 0
b 0
f 0
wmc 9

3 Methods

Rating   Name   Duplication   Size   Complexity  
A composeText() 0 17 4
A getDescription() 0 3 1
A composeHtml() 0 21 4
1
<?php
2
/**
3
 * sysPass
4
 *
5
 * @author    nuxsmin
6
 * @link      https://syspass.org
7
 * @copyright 2012-2018, Rubén Domínguez nuxsmin@$syspass.org
8
 *
9
 * This file is part of sysPass.
10
 *
11
 * sysPass is free software: you can redistribute it and/or modify
12
 * it under the terms of the GNU General Public License as published by
13
 * the Free Software Foundation, either version 3 of the License, or
14
 * (at your option) any later version.
15
 *
16
 * sysPass is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU General Public License
22
 *  along with sysPass.  If not, see <http://www.gnu.org/licenses/>.
23
 */
24
25
namespace SP\Core\Messages;
26
27
/**
28
 * Class NoticeMessage
29
 *
30
 * @package SP\Core\Messages
31
 */
32
final class NotificationMessage extends MessageBase
33
{
34
    /**
35
     * Componer un mensaje en formato HTML
36
     *
37
     * @return string
38
     */
39
    public function composeHtml()
40
    {
41
        $formatter = new HtmlFormatter();
42
43
        $message = '<div class="notice-message" style="font-family: Helvetica, Arial, sans-serif">';
44
45
        if ($this->title) {
46
            $message .= '<h3>' . $this->title . '</h3>';
47
        }
48
49
        if (!empty($this->description)) {
50
            $message .= '<div class="notice-description">' . $this->getDescription($formatter) . '</div>';
51
        }
52
53
        if (!empty($this->footer)) {
54
            $message .= '<footer>' . implode('<br>', $this->footer) . '</footer>';
55
        }
56
57
        $message .= '</div>';
58
59
        return $message;
60
    }
61
62
    /**
63
     * @param FormatterInterface $formatter
64
     * @param bool               $translate
65
     *
66
     * @return string
67
     */
68
    public function getDescription(FormatterInterface $formatter, $translate = false): string
69
    {
70
        return $formatter->formatDescription($this->description, $translate);
71
    }
72
73
    /**
74
     * Componer un mensaje en formato texto
75
     *
76
     * @param string $delimiter
77
     *
78
     * @return string
79
     */
80
    public function composeText($delimiter = PHP_EOL)
81
    {
82
        $parts = [];
83
84
        if ($this->title) {
85
            $parts[] = $this->title;
86
        }
87
88
        if (!empty($this->description)) {
89
            $parts[] = implode($delimiter, $this->description);
90
        }
91
92
        if (!empty($this->footer)) {
93
            $parts[] = implode($delimiter, $this->footer);
94
        }
95
96
        return implode($delimiter, $parts);
97
    }
98
}