Completed
Pull Request — master (#6)
by
unknown
04:26
created

SnsMessage::getSenderID()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
136
137
        return $this;
138
    }
139
}
140