SimpleContent::addHtml()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpEmail\Content;
6
7
use PhpEmail\Content;
8
use PhpEmail\Content\SimpleContent\Message;
9
10
/**
11
 * The standard content of an email, as we have always used it. All that is required is some HTML or a text string.
12
 */
13
class SimpleContent implements Content\Contracts\SimpleContent
14
{
15
    /**
16
     * @var Message|null
17
     */
18
    private $html;
19
20
    /**
21
     * @var Message|null
22
     */
23
    private $text;
24
25
    /**
26
     * SimpleContent constructor.
27
     *
28
     * @param Message|null $html
29
     * @param Message|null $text
30
     */
31 4
    public function __construct(?Message $html, ?Message $text)
32
    {
33 4
        $this->html = $html;
34 4
        $this->text = $text;
35
    }
36
37
    /**
38
     * @param string $html
39
     * @param string $charset
40
     *
41
     * @return SimpleContent
42
     */
43 2
    public static function html(string $html, string $charset = Message::DEFAULT_CHARSET): self
44
    {
45 2
        return new self(new Message($html, $charset), null);
46
    }
47
48
    /**
49
     * @param string $html
50
     * @param string $charset
51
     *
52
     * @return SimpleContent
53
     */
54 1
    public function addHtml(string $html, string $charset = Message::DEFAULT_CHARSET): self
55
    {
56 1
        return new self(new Message($html, $charset), clone $this->text);
57
    }
58
59
    /**
60
     * @param string $text
61
     * @param string $charset
62
     *
63
     * @return SimpleContent
64
     */
65 2
    public static function text(string $text, string $charset = Message::DEFAULT_CHARSET): self
66
    {
67 2
        return new self(null, new Message($text, $charset));
68
    }
69
70
    /**
71
     * @param string $text
72
     * @param string $charset
73
     *
74
     * @return SimpleContent
75
     */
76 1
    public function addText(string $text, string $charset = Message::DEFAULT_CHARSET): self
77
    {
78 1
        return new self(clone $this->html, new Message($text, $charset));
79
    }
80
81
    /**
82
     * @return Message|null
83
     */
84 4
    public function getHtml(): ?Message
85
    {
86 4
        return $this->html;
87
    }
88
89
    /**
90
     * @return Message|null
91
     */
92 4
    public function getText(): ?Message
93
    {
94 4
        return $this->text;
95
    }
96
}
97