Failed Conditions
Pull Request — develop (#23)
by Jeffrey
03:42
created

MessageOptions   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Test Coverage

Coverage 96.43%

Importance

Changes 0
Metric Value
eloc 23
dl 0
loc 73
ccs 27
cts 28
cp 0.9643
rs 10
c 0
b 0
f 0
wmc 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A hasTextTemplate() 0 3 1
A getSubject() 0 7 2
A hasSubject() 0 3 1
A __construct() 0 10 1
A fromArray() 0 7 1
A getTextTemplate() 0 3 1
A getParticipants() 0 3 1
A hasHtmlTemplate() 0 3 1
A getHtmlTemplate() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FH\Bundle\MailerBundle\Email;
6
7
use FH\Bundle\MailerBundle\Exception\InvalidArgumentException;
8
9
final class MessageOptions
10
{
11
    /** @var string|null */
12
    private $subject;
13
14
    /** @var string|null */
15
    private $htmlTemplate;
16
17
    /** @var string|null */
18
    private $textTemplate;
19
20
    /** @var Participants */
21
    private $participants;
22
23 1
    public static function fromArray(array $messageOptions): self
24
    {
25 1
        return new self(
26 1
            $messageOptions['subject'],
27 1
            $messageOptions['html_template'] ?? null,
28 1
            $messageOptions['text_template'] ?? null,
29 1
            Participants::fromArray($messageOptions['participants'])
30
        );
31
    }
32
33 1
    public function __construct(
34
        ?string $subject,
35
        ?string $htmlTemplate,
36
        ?string $textTemplate,
37
        Participants $participants
38
    ) {
39 1
        $this->subject = $subject;
40 1
        $this->htmlTemplate = $htmlTemplate;
41 1
        $this->textTemplate = $textTemplate;
42 1
        $this->participants = $participants;
43 1
    }
44
45 1
    public function getSubject(): string
46
    {
47 1
        if (!\is_string($this->subject)) {
48
            throw new InvalidArgumentException('Invalid subject');
49
        }
50
51 1
        return $this->subject;
52
    }
53
54 1
    public function hasSubject(): bool
55
    {
56 1
        return \is_string($this->subject);
57
    }
58
59 1
    public function getHtmlTemplate(): ?string
60
    {
61 1
        return $this->htmlTemplate;
62
    }
63
64 1
    public function hasHtmlTemplate(): bool
65
    {
66 1
        return \is_string($this->htmlTemplate);
67
    }
68
69 1
    public function getTextTemplate(): ?string
70
    {
71 1
        return $this->textTemplate;
72
    }
73
74 1
    public function hasTextTemplate(): bool
75
    {
76 1
        return \is_string($this->textTemplate);
77
    }
78
79 1
    public function getParticipants(): Participants
80
    {
81 1
        return $this->participants;
82
    }
83
}
84