Completed
Push — master ( d210a4...3d143c )
by Barry vd.
07:35 queued 05:30
created

ApnMessage   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 167
Duplicated Lines 0 %

Coupling/Cohesion

Components 5
Dependencies 0

Test Coverage

Coverage 19.35%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 9
c 2
b 0
f 0
lcom 5
cbo 0
dl 0
loc 167
ccs 6
cts 31
cp 0.1935
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A title() 0 6 1
A create() 0 4 1
A body() 0 6 1
A badge() 0 6 1
A sound() 0 6 1
A custom() 0 6 1
A setCustom() 0 6 1
A action() 0 7 1
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
     * Additional data of the notification.
37
     *
38
     * @var array
39
     */
40
    public $custom = [];
41
42
    /**
43
     * @param string|null $title
44
     * @param string|null $body
45
     * @param array $custom
46
     * @param null|int $badge
47
     *
48
     * @return static
49
     */
50
    public static function create($title = null, $body = null, $custom = [], $badge = null)
51
    {
52
        return new static($title, $body, $custom, $badge);
53
    }
54
55
    /**
56
     * @param string|null $title
57
     * @param string|null $body
58
     * @param array $custom
59
     * @param null|int $badge
60
     *
61
     * @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...
62
     */
63 1
    public function __construct($title = null, $body = null, $custom = [], $badge = null)
64
    {
65 1
        $this->title = $title;
66 1
        $this->body = $body;
67 1
        $this->custom = $custom;
68 1
        $this->badge = $badge;
69 1
    }
70
71
    /**
72
     * Set the alert title of the notification.
73
     *
74
     * @param string $title
75
     *
76
     * @return $this
77
     */
78
    public function title($title)
79
    {
80
        $this->title = $title;
81
82
        return $this;
83
    }
84
85
    /**
86
     * Set the alert message of the notification.
87
     *
88
     * @param string $body
89
     *
90
     * @return $this
91
     */
92
    public function body($body)
93
    {
94
        $this->body = $body;
95
96
        return $this;
97
    }
98
99
    /**
100
     * Set the badge of the notification.
101
     *
102
     * @param int $badge
103
     *
104
     * @return $this
105
     */
106
    public function badge($badge)
107
    {
108
        $this->badge = $badge;
109
110
        return $this;
111
    }
112
113
    /**
114
     * Set the sound for the notification.
115
     *
116
     * @param string|null $sound
117
     *
118
     * @return $this
119
     */
120
    public function sound($sound)
121
    {
122
        $this->sound = $sound;
123
124
        return $this;
125
    }
126
127
    /**
128
     * Add custom data to the notification.
129
     *
130
     * @param string $key
131
     * @param mixed $value
132
     *
133
     * @return $this
134
     */
135
    public function custom($key, $value)
136
    {
137
        $this->custom[$key] = $value;
138
139
        return $this;
140
    }
141
142
    /**
143
     * Override the data of the notification.
144
     *
145
     * @param array $custom
146
     *
147
     * @return $this
148
     */
149
    public function setCustom($custom)
150
    {
151
        $this->custom = $custom;
152
153
        return $this;
154
    }
155
156
    /**
157
     * Add an action to the notification.
158
     *
159
     * @param string $action
160
     * @param mixed $params
161
     *
162
     * @return $this
163
     */
164
    public function action($action, $params = null)
165
    {
166
        return $this->custom('action', [
167
            'action' => $action,
168
            'params' => $params,
169
        ]);
170
    }
171
}
172