SnsMessage   A
last analyzed

Complexity

Total Complexity 16

Size/Duplication

Total Lines 157
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 28
c 2
b 0
f 0
dl 0
loc 157
ccs 28
cts 28
cp 1
rs 10
wmc 16

11 Methods

Rating   Name   Duplication   Size   Complexity  
A getBody() 0 3 1
A create() 0 3 1
A originationNumber() 0 5 1
A getSender() 0 3 1
A getOriginationNumber() 0 3 1
A getDeliveryType() 0 3 2
A body() 0 5 1
A __construct() 0 10 5
A promotional() 0 5 1
A transactional() 0 5 1
A sender() 0 5 1
1
<?php
2
3
namespace NotificationChannels\AwsSns;
4
5
class SnsMessage
6
{
7
    const PROMOTIONAL_SMS_TYPE = 'Promotional';
8
9
    const TRANSACTIONAL_SMS_TYPE = 'Transactional';
10
11
    /**
12
     * The body of the message.
13
     *
14
     * @var string
15
     */
16
    protected $body = '';
17
18
    /**
19
     * The delivery type of the message.
20
     *
21
     * @var bool
22
     */
23
    protected $promotional = true;
24
25
    /**
26
     * The sender identification of the message.
27
     *
28
     * @var string
29
     */
30
    protected $sender = '';
31
32 16
    /**
33
     * The origination number of the message.
34 16
     *
35 5
     * @var string
36
     */
37
    protected $originationNumber = '';
38 16
39 11
    public function __construct($content)
40 5
    {
41 5
        if (is_string($content)) {
42
            $this->body($content);
43
        }
44
45 16
        if (is_array($content)) {
46
            foreach ($content as $property => $value) {
47
                if (method_exists($this, $property)) {
48
                    $this->{$property}($value);
49
                }
50
            }
51
        }
52 8
    }
53
54 8
    /**
55
     * Creates a new instance of the message.
56
     *
57
     * @return SnsMessage
58
     */
59
    public static function create(array $data = [])
60
    {
61
        return new self($data);
62 11
    }
63
64 11
    /**
65
     * Sets the message body.
66 11
     *
67
     * @return $this
68
     */
69
    public function body(string $content)
70
    {
71
        $this->body = trim($content);
72
73
        return $this;
74 8
    }
75
76 8
    /**
77
     * Get the message body.
78
     *
79
     * @return string
80
     */
81
    public function getBody()
82
    {
83
        return $this->body;
84 1
    }
85
86 1
    /**
87
     * Sets the message delivery type as promotional.
88 1
     *
89
     * @return $this
90
     */
91
    public function promotional(bool $active = true)
92
    {
93
        $this->promotional = $active;
94
95
        return $this;
96 3
    }
97
98 3
    /**
99
     * Sets the message delivery type as transactional.
100 3
     *
101
     * @return $this
102
     */
103
    public function transactional(bool $active = true)
104
    {
105
        $this->promotional = ! $active;
106
107
        return $this;
108 7
    }
109
110 7
    /**
111
     * Get the message delivery type.
112
     *
113
     * @return string
114
     */
115
    public function getDeliveryType()
116
    {
117
        return $this->promotional ? self::PROMOTIONAL_SMS_TYPE : self::TRANSACTIONAL_SMS_TYPE;
118 3
    }
119
120 3
    /**
121
     * Sets the message sender identification.
122 3
     *
123
     * @return $this
124
     */
125
    public function sender(string $sender)
126
    {
127
        $this->sender = $sender;
128
129
        return $this;
130 6
    }
131
132 6
    /**
133
     * Get the message sender identification.
134
     *
135
     * @return string
136
     */
137
    public function getSender()
138
    {
139
        return $this->sender;
140
    }
141
142
    /**
143
     * Sets the message origination number identification.
144
     *
145
     * @return $this
146
     */
147
    public function originationNumber(string $originationNumber)
148
    {
149
        $this->originationNumber = $originationNumber;
150
151
        return $this;
152
    }
153
154
    /**
155
     * Get the message origination number identification.
156
     *
157
     * @return string
158
     */
159
    public function getOriginationNumber()
160
    {
161
        return $this->originationNumber;
162
    }
163
}
164