UserMailable::__construct()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 21
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 21
rs 9.0534
c 0
b 0
f 0
cc 4
eloc 15
nc 3
nop 5
1
<?php
2
3
/*
4
 * This file is part of the BenGorUser package.
5
 *
6
 * (c) Beñat Espiña <[email protected]>
7
 * (c) Gorka Laucirica <[email protected]>
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
namespace BenGorUser\User\Domain\Model;
14
15
use BenGorUser\User\Domain\Model\Exception\UserEmailInvalidException;
16
17
/**
18
 * User mailable domain class.
19
 *
20
 * @author Beñat Espiña <[email protected]>
21
 * @author Gorka Laucirica <[email protected]>
22
 */
23
class UserMailable
24
{
25
    /**
26
     * The receiver or receivers.
27
     *
28
     * @var array|UserEmail
29
     */
30
    private $to;
31
32
    /**
33
     * The from address.
34
     *
35
     * @var UserEmail
36
     */
37
    private $from;
38
39
    /**
40
     * The subject.
41
     *
42
     * @var string
43
     */
44
    private $subject;
45
46
    /**
47
     * The body in plain text.
48
     *
49
     * @var string
50
     */
51
    private $bodyText;
52
53
    /**
54
     * The body in HTML.
55
     *
56
     * @var string|null
57
     */
58
    private $bodyHtml;
59
60
    /**
61
     * Constructor.
62
     *
63
     * @param array|UserEmail $to        The receiver or receivers
64
     * @param UserEmail       $from      The from address
65
     * @param string          $aSubject  The subject
66
     * @param string          $aBodyText The body in plain text
67
     * @param string          $aBodyHtml The body in HTML, can be null
0 ignored issues
show
Documentation introduced by
Should the type for parameter $aBodyHtml not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
68
     */
69
    public function __construct($to, UserEmail $from, $aSubject, $aBodyText, $aBodyHtml = null)
70
    {
71
        if (is_array($to)) {
72
            $this->to = array_map(function ($receiver) {
73
                if (!$receiver instanceof UserEmail) {
74
                    throw new UserEmailInvalidException();
75
                }
76
77
                return $receiver;
78
            }, $to);
79
        } elseif ($to instanceof UserEmail) {
80
            $this->to = $to;
81
        } else {
82
            throw new UserEmailInvalidException();
83
        }
84
85
        $this->from = $from;
86
        $this->subject = $aSubject;
87
        $this->bodyText = $aBodyText;
88
        $this->bodyHtml = $aBodyHtml;
89
    }
90
91
    /**
92
     * Gets the receiver or receivers.
93
     *
94
     * @return array|UserEmail
95
     */
96
    public function to()
97
    {
98
        return $this->to;
99
    }
100
101
    /**
102
     * Gets the from address.
103
     *
104
     * @return UserEmail
105
     */
106
    public function from()
107
    {
108
        return $this->from;
109
    }
110
111
    /**
112
     * Gets the subject.
113
     *
114
     * @return string
115
     */
116
    public function subject()
117
    {
118
        return $this->subject;
119
    }
120
121
    /**
122
     * Gets the body in plain text.
123
     *
124
     * @return string
125
     */
126
    public function bodyText()
127
    {
128
        return $this->bodyText;
129
    }
130
131
    /**
132
     * Gets the body in HTML.
133
     *
134
     * @return string|null
135
     */
136
    public function bodyHtml()
137
    {
138
        return $this->bodyHtml;
139
    }
140
}
141