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

MailMessage::getDescription()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
rs 10
c 0
b 0
f 0
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 MailMessage
29
 *
30
 * @package SP\Core\Messages
31
 */
32
final class MailMessage extends MessageBase implements MessageInterface
33
{
34
    /**
35
     * Adds a blank description line
36
     */
37
    public function addDescriptionLine()
38
    {
39
        $this->description[] = '';
40
    }
41
42
    /**
43
     * Componer un mensaje en formato HTML
44
     *
45
     * @return string
46
     */
47
    public function composeHtml()
48
    {
49
        $formatter = new HtmlFormatter();
50
51
        $message = '<div class="mail-message" style="font-family: Helvetica, Arial, sans-serif">';
52
        $message .= '<h3>' . $this->title . '</h3>';
53
        $message .= '<div class="mail-description">' . $this->getDescription($formatter, true) . '</div>';
54
        $message .= '<footer>' . implode('<br>', $this->footer) . '</footer>';
55
        $message .= '</div>';
56
57
        return $message;
58
    }
59
60
    /**
61
     * @param FormatterInterface $formatter
62
     * @param bool               $translate
63
     *
64
     * @return string
65
     */
66
    public function getDescription(FormatterInterface $formatter, $translate = false): string
67
    {
68
        return $formatter->formatDescription($this->description, $translate);
69
    }
70
71
    /**
72
     * Componer un mensaje en formato texto
73
     *
74
     * @param string $delimiter
75
     *
76
     * @return string
77
     */
78
    public function composeText($delimiter = PHP_EOL)
79
    {
80
        $formatter = new TextFormatter($delimiter);
81
82
        return $this->title
83
            . $delimiter
84
            . $formatter->formatDescription($this->description)
85
            . $delimiter
86
            . implode($delimiter, $this->footer);
87
    }
88
}