Completed
Pull Request — master (#3)
by
unknown
04:36
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 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
     * @param  array      $data
44
     * @return SnsMessage
45
     */
46 6
    public static function create(array $data = [])
47
    {
48 6
        return new self($data);
49
    }
50
51
    /**
52
     * Sets the message body.
53
     *
54
     * @param  string $content
55
     * @return $this
56
     */
57 10
    public function body(string $content)
58
    {
59 10
        $this->body = trim($content);
60
61 10
        return $this;
62
    }
63
64
    /**
65
     * Get the message body.
66
     *
67
     * @return string
68
     */
69 7
    public function getBody()
70
    {
71 7
        return $this->body;
72
    }
73
74
    /**
75
     * Get the SMS delivery type.
76
     *
77
     * @return string
78
     */
79 6
    public function getDeliveryType()
80
    {
81 6
        return $this->promotional ? self::PROMOTIONAL_SMS_TYPE : self::TRANSACTIONAL_SMS_TYPE;
82
    }
83
84
    /**
85
     * Sets the SMS delivery type as promotional.
86
     *
87
     * @param  bool  $active
88
     * @return $this
89
     */
90 1
    public function promotional(bool $active = true)
91
    {
92 1
        $this->promotional = $active;
93
94 1
        return $this;
95
    }
96
97
    /**
98
     * Sets the SMS delivery type as transactional.
99
     *
100
     * @param  bool  $active
101
     * @return $this
102
     */
103 3
    public function transactional(bool $active = true)
104
    {
105 3
        $this->promotional = ! $active;
106
107 3
        return $this;
108
    }
109
}
110