Completed
Pull Request — master (#48)
by Frederik
02:13
created

FormattedMessageFactory::createMessageHumanReadable()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 8
cts 8
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 8
nc 2
nop 0
crap 2
1
<?php
2
declare(strict_types=1);
3
4
namespace Genkgo\Mail;
5
6
use Genkgo\Mail\Mime\EmbeddedImage;
7
use Genkgo\Mail\Mime\PartInterface;
8
9
/**
10
 * This class is superseded by MessageBodyCollection. Since there is no need to remove or deprecate this
11
 * class, it will remain part of the package.
12
 */
13
final class FormattedMessageFactory
14
{
15
    /**
16
     * @var MessageBodyCollection
17
     */
18
    private $messageBody;
19
20 2
    public function __construct()
21
    {
22 2
        $this->messageBody = new MessageBodyCollection();
23 2
    }
24
25
    /**
26
     * @param string $html
27
     * @return FormattedMessageFactory
28
     */
29 2
    public function withHtml(string $html): FormattedMessageFactory
30
    {
31 2
        $clone = clone $this;
32 2
        $clone->messageBody = $clone->messageBody
33 2
            ->withHtml($html)
34 2
            ->withAlternativeText(AlternativeText::fromHtml($html));
35 2
        return $clone;
36
    }
37
38
    /**
39
     * @param string $html
40
     * @return FormattedMessageFactory
41
     */
42 1
    public function withHtmlAndNoGeneratedAlternativeText(string $html): FormattedMessageFactory
43
    {
44 1
        $clone = clone $this;
45 1
        $clone->messageBody = $clone->messageBody->withHtml($html);
46 1
        return $clone;
47
    }
48
49
    /**
50
     * @param AlternativeText $text
51
     * @return FormattedMessageFactory
52
     */
53 1
    public function withAlternativeText(AlternativeText $text): FormattedMessageFactory
54
    {
55 1
        $clone = clone $this;
56 1
        $clone->messageBody = $clone->messageBody->withAlternativeText($text);
57 1
        return $clone;
58
    }
59
60
    /**
61
     * @param PartInterface $part
62
     * @return FormattedMessageFactory
63
     */
64 2
    public function withAttachment(PartInterface $part): FormattedMessageFactory
65
    {
66 2
        $clone = clone $this;
67 2
        $clone->messageBody = $clone->messageBody->withAttachment($part);
68 2
        return $clone;
69
    }
70
71
    /**
72
     * @param EmbeddedImage $embeddedImage
73
     * @return FormattedMessageFactory
74
     */
75 2
    public function withEmbeddedImage(EmbeddedImage $embeddedImage): FormattedMessageFactory
76
    {
77 2
        $clone = clone $this;
78 2
        $clone->messageBody = $clone->messageBody->withEmbeddedImage($embeddedImage);
79 2
        return $clone;
80
    }
81
82
    /**
83
     * @return MessageInterface
84
     */
85 1
    public function createMessage(): MessageInterface
86
    {
87 1
        return $this->messageBody->createMessage();
88
    }
89
}
90