Completed
Pull Request — master (#7)
by
unknown
04:03 queued 21s
created

SnsMessage::create()   A

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 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
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 default delivery type for the SMS message.
13
     *
14
     * @var bool
15
     */
16
    protected $promotional = true;
17
18
    /**
19
     * The default Sender ID for the SMS message.
20
     *
21
     * @var string
22
     */
23
    protected $senderID = 'NOTICE';
24
25
    /**
26
     * The body of the message.
27
     *
28
     * @var string
29
     */
30
    protected $body = '';
31
32 15
    public function __construct($content)
33
    {
34 15
        if (is_string($content)) {
35 4
            $this->body($content);
36
        }
37
38 15
        if (is_array($content)) {
39 11
            foreach ($content as $property => $value) {
40 5
                if (method_exists($this, $property)) {
41 5
                    $this->{$property}($value);
42
                }
43
            }
44
        }
45 15
    }
46
47
    /**
48
     * Creates a new instance of the message.
49
     *
50
     * @param array $data
51
     * @return SnsMessage
52
     */
53 8
    public static function create(array $data = [])
54
    {
55 8
        return new self($data);
56
    }
57
58
    /**
59
     * Sets the message body.
60
     *
61
     * @param string $content
62
     * @return $this
63
     */
64 10
    public function body(string $content)
65
    {
66 10
        $this->body = trim($content);
67
68 10
        return $this;
69
    }
70
71
    /**
72
     * Get the message body.
73
     *
74
     * @return string
75
     */
76 7
    public function getBody()
77
    {
78 7
        return $this->body;
79
    }
80
81
    /**
82
     * Get the SMS delivery type.
83
     *
84
     * @return string
85
     */
86 6
    public function getDeliveryType()
87
    {
88 6
        return $this->promotional ? self::PROMOTIONAL_SMS_TYPE : self::TRANSACTIONAL_SMS_TYPE;
89
    }
90
91
    /**
92
     * Get the SMS Sender ID.
93
     *
94
     * @return string
95
     */
96 5
    public function getSenderID()
97
    {
98 5
        return $this->senderID;
99
    }
100
101
    /**
102
     * Sets the SMS delivery type as promotional.
103
     *
104
     * @param bool $active
105
     * @return $this
106
     */
107 1
    public function promotional(bool $active = true)
108
    {
109 1
        $this->promotional = $active;
110
111 1
        return $this;
112
    }
113
114
    /**
115
     * Sets the SMS delivery type as transactional.
116
     *
117
     * @param bool $active
118
     * @return $this
119
     */
120 3
    public function transactional(bool $active = true)
121
    {
122 3
        $this->promotional = ! $active;
123
124 3
        return $this;
125
    }
126
127
    /**
128
     * Sets the SMS Sender ID.
129
     *
130
     * @param string $sender
131
     * @return $this
132
     */
133 4
    public function sender(string $sender = 'NOTICE')
134
    {
135 4
        $this->senderID = $sender;
136
137 4
        return $this;
138
    }
139
}
140