Completed
Push — master ( 77d207...af47af )
by Atymic
05:06
created

SnsMessage::transactional()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
ccs 3
cts 3
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 body of the message.
20
     *
21
     * @var string
22
     */
23
    protected $body = '';
24
25 13
    public function __construct($content)
26
    {
27 13
        if (is_string($content)) {
28 5
            $this->body($content);
29
        }
30
31 13
        if (is_array($content)) {
32 8
            foreach ($content as $property => $value) {
33 4
                if (method_exists($this, $property)) {
34 4
                    $this->{$property}($value);
35
                }
36
            }
37
        }
38 13
    }
39
40
    /**
41
     * Creates a new instance of the message.
42
     *
43
     * @return SnsMessage
44
     */
45 6
    public static function create(array $data = [])
46
    {
47 6
        return new self($data);
48
    }
49
50
    /**
51
     * Sets the message body.
52
     *
53
     * @return $this
54
     */
55 10
    public function body(string $content)
56
    {
57 10
        $this->body = trim($content);
58
59 10
        return $this;
60
    }
61
62
    /**
63
     * Get the message body.
64
     *
65
     * @return string
66
     */
67 7
    public function getBody()
68
    {
69 7
        return $this->body;
70
    }
71
72
    /**
73
     * Get the SMS delivery type.
74
     *
75
     * @return string
76
     */
77 6
    public function getDeliveryType()
78
    {
79 6
        return $this->promotional ? self::PROMOTIONAL_SMS_TYPE : self::TRANSACTIONAL_SMS_TYPE;
80
    }
81
82
    /**
83
     * Sets the SMS delivery type as promotional.
84
     *
85
     * @return $this
86
     */
87 1
    public function promotional(bool $active = true)
88
    {
89 1
        $this->promotional = $active;
90
91 1
        return $this;
92
    }
93
94
    /**
95
     * Sets the SMS delivery type as transactional.
96
     *
97
     * @return $this
98
     */
99 3
    public function transactional(bool $active = true)
100
    {
101 3
        $this->promotional = ! $active;
102
103 3
        return $this;
104
    }
105
}
106