Completed
Push — master ( edcf6e...5510ac )
by Barry vd.
05:01
created

ApnMessage::category()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
ccs 0
cts 0
cp 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 2
1
<?php
2
3
namespace NotificationChannels\Apn;
4
5
class ApnMessage
6
{
7
    /**
8
     * The title of the notification.
9
     *
10
     * @var string
11
     */
12
    public $title;
13
14
    /**
15
     * The body of the notification.
16
     *
17
     * @var string
18
     */
19
    public $body;
20
21
    /**
22
     * The badge of the notification.
23
     *
24
     * @var int
25
     */
26
    public $badge;
27
28
    /**
29
     * The sound for the notification.
30
     *
31
     * @var string|null
32
     */
33
    public $sound;
34
35
    /**
36
     * The category for action button
37
     * 
38
     * @var string|null
39
     * */
40
    public $category;
41
42
    /**
43
     * Additional data of the notification.
44
     *
45
     * @var array
46
     */
47
    public $custom = [];
48
49
    /**
50
     * @param string|null $title
51
     * @param string|null $body
52
     * @param array $custom
53
     * @param null|int $badge
54
     *
55
     * @return static
56
     */
57
    public static function create($title = null, $body = null, $custom = [], $badge = null)
58
    {
59
        return new static($title, $body, $custom, $badge);
60
    }
61
62
    /**
63 1
     * @param string|null $title
64
     * @param string|null $body
65 1
     * @param array $custom
66 1
     * @param null|int $badge
67 1
     *
68 1
     * @return static
0 ignored issues
show
Comprehensibility Best Practice introduced by Barry vd. Heuvel
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
69 1
     */
70
    public function __construct($title = null, $body = null, $custom = [], $badge = null)
71
    {
72
        $this->title = $title;
73
        $this->body = $body;
74
        $this->custom = $custom;
75
        $this->badge = $badge;
76
    }
77
78
    /**
79
     * Set the alert title of the notification.
80
     *
81
     * @param string $title
82
     *
83
     * @return $this
84
     */
85
    public function title($title)
86
    {
87
        $this->title = $title;
88
89
        return $this;
90
    }
91
92
    /**
93
     * Set the alert message of the notification.
94
     *
95
     * @param string $body
96
     *
97
     * @return $this
98
     */
99
    public function body($body)
100
    {
101
        $this->body = $body;
102
103
        return $this;
104
    }
105
106
    /**
107
     * Set the badge of the notification.
108
     *
109
     * @param int $badge
110
     *
111
     * @return $this
112
     */
113
    public function badge($badge)
114
    {
115
        $this->badge = $badge;
116
117
        return $this;
118
    }
119
120
    /**
121
     * Set the sound for the notification.
122
     *
123
     * @param string|null $sound
124
     *
125
     * @return $this
126
     */
127
    public function sound($sound)
128
    {
129
        $this->sound = $sound;
130
131
        return $this;
132
    }
133
134
    /**
135
     * Set category for this notification
136
     * 
137
     * @param string|null $category
138
     * 
139
     * @return $this
140
     * */
141
    public function category($category)
142
    {
143
        $this->category = $category;
144
145
        return $this;
146
    }
147
148
    /**
149
     * Add custom data to the notification.
150
     *
151
     * @param string $key
152
     * @param mixed $value
153
     *
154
     * @return $this
155
     */
156
    public function custom($key, $value)
157
    {
158
        $this->custom[$key] = $value;
159
160
        return $this;
161
    }
162
163
    /**
164
     * Override the data of the notification.
165
     *
166
     * @param array $custom
167
     *
168
     * @return $this
169
     */
170
    public function setCustom($custom)
171
    {
172
        $this->custom = $custom;
173
174
        return $this;
175
    }
176
177
    /**
178
     * Add an action to the notification.
179
     *
180
     * @param string $action
181
     * @param mixed $params
182
     *
183
     * @return $this
184
     */
185
    public function action($action, $params = null)
186
    {
187
        return $this->custom('action', [
188
            'action' => $action,
189
            'params' => $params,
190
        ]);
191
    }
192
}
193