Completed
Push — master ( 7c85b2...91e0f6 )
by Aly
05:47
created

ExpoMessage::disableSound()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
c 0
b 0
f 0
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
crap 1
1
<?php
2
3
namespace NotificationChannels\ExpoPushNotifications;
4
5
class ExpoMessage
6
{
7
    /**
8
     * The message body.
9
     *
10
     * @var string
11
     */
12
    protected $body;
13
14
    /**
15
     * The sound to play when the recipient receives this notification.
16
     *
17
     * @var string|null
18
     */
19
    protected $sound = 'default';
20
21
    /**
22
     * The number to display next to the push notification (iOS).
23
     * Specify zero to clear the badge.
24
     *
25
     * @var int
26
     */
27
    protected $badge = 0;
28
29
    /**
30
     * The number of seconds for which the message may be kept around for redelivery if it has not been delivered yet.
31
     *
32
     * @var int
33
     */
34
    protected $ttl = 0;
35
36
    /**
37
     * @param string $body
38
     *
39
     * @return static
40
     */
41 1
    public static function create($body = '')
42
    {
43 1
        return new static($body);
44
    }
45
46
    /**
47
     * ExpoMessage constructor.
48
     *
49
     * @param string $body
50
     */
51 9
    public function __construct(string $body = '')
52
    {
53 9
        $this->body = $body;
54 9
    }
55
56
    /**
57
     * Set the message body.
58
     *
59
     * @param string $value
60
     *
61
     * @return $this
62
     */
63 1
    public function body(string $value)
64
    {
65 1
        $this->body = $value;
66
67 1
        return $this;
68
    }
69
70
    /**
71
     * Enable the message sound.
72
     *
73
     * @return $this
74
     */
75 1
    public function enableSound()
76
    {
77 1
        $this->sound = 'default';
78
79 1
        return $this;
80
    }
81
82
    /**
83
     * Disable the message sound.
84
     *
85
     * @return $this
86
     */
87 2
    public function disableSound()
88
    {
89 2
        $this->sound = null;
90
91 2
        return $this;
92
    }
93
94
    /**
95
     * Set the message badge (iOS).
96
     *
97
     * @param int $value
98
     *
99
     * @return $this
100
     */
101 1
    public function badge(int $value)
102
    {
103 1
        $this->badge = $value;
104
105 1
        return $this;
106
    }
107
108
    /**
109
     * Set the time to live of the notification
110
     *
111
     * @param int $ttl
112
     *
113
     * @return $this
114
     */
115 1
    public function setTtl(int $ttl)
116
    {
117 1
        $this->ttl = $ttl;
118
119 1
        return $this;
120
    }
121
122
    /**
123
     * Get an array representation of the message
124
     *
125
     * @return array
126
     */
127 9
    public function toArray()
128
    {
129
        return [
130 9
            'body'  =>  $this->body,
131 9
            'sound' =>  $this->sound,
132 9
            'badge' =>  $this->badge,
133 9
            'ttl'   =>  $this->ttl,
134
        ];
135
    }
136
}
137