Completed
Pull Request — master (#56)
by Vladimir
04:42
created

Notification::withPushType()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types = 1);
4
5
/*
6
 * This file is part of the AppleApnPush package
7
 *
8
 * (c) Vitaliy Zhuk <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code
12
 */
13
14
namespace Apple\ApnPush\Model;
15
16
/**
17
 * Send this notification to device.
18
 */
19
class Notification
20
{
21
    /**
22
     * @var Payload
23
     */
24
    private $payload;
25
26
    /**
27
     * @var ApnId
28
     */
29
    private $apnId;
30
31
    /**
32
     * @var Priority
33
     */
34
    private $priority;
35
36
    /**
37
     * @var Expiration
38
     */
39
    private $expiration;
40
41
    /**
42
     * @var CollapseId
43
     */
44
    private $collapseId;
45
46
    /**
47
     * @var PushType
48
     */
49
    private $pushType;
50
    
51
    public function __construct(
52
        Payload $payload,
53
        ?ApnId $apnId = null,
54
        ?Priority $priority = null,
55
        ?Expiration $expiration = null,
56
        ?CollapseId $collapseId = null,
57
        ?PushType $pushType = null
58
    ) {
59
        $this->payload = $payload;
60
        $this->priority = $priority;
61
        $this->apnId = $apnId;
62
        $this->expiration = $expiration;
63
        $this->collapseId = $collapseId;
64
        $this->pushType = $pushType;
65
    }
66
67
    /**
68
     * Create new notification with body only
69
     *
70
     * @param string $body
71
     *
72
     * @return Notification
73
     */
74
    public static function createWithBody(string $body): Notification
75
    {
76
        return new self(Payload::createWithBody($body));
77
    }
78
79
    /**
80
     * Set payload
81
     *
82
     * @param Payload $payload
83
     *
84
     * @return Notification
85
     */
86
    public function withPayload(Payload $payload): Notification
87
    {
88
        $cloned = clone $this;
89
90
        $cloned->payload = $payload;
91
92
        return $cloned;
93
    }
94
95
    /**
96
     * Get payload
97
     *
98
     * @return Payload
99
     */
100
    public function getPayload(): Payload
101
    {
102
        return $this->payload;
103
    }
104
105
    /**
106
     * Set apn identifier
107
     *
108
     * @param ApnId $apnId
109
     *
110
     * @return Notification
111
     */
112
    public function withApnId(ApnId $apnId = null): Notification
113
    {
114
        $cloned = clone $this;
115
116
        $cloned->apnId = $apnId;
117
118
        return $cloned;
119
    }
120
121
    /**
122
     * Get identifier of notification
123
     *
124
     * @return ApnId
125
     */
126
    public function getApnId(): ?ApnId
127
    {
128
        return $this->apnId;
129
    }
130
131
    /**
132
     * Set priority
133
     *
134
     * @param Priority $priority
135
     *
136
     * @return Notification
137
     */
138
    public function withPriority(Priority $priority = null): Notification
139
    {
140
        $cloned = clone $this;
141
142
        $cloned->priority = $priority;
143
144
        return $cloned;
145
    }
146
147
    /**
148
     * Get priority
149
     *
150
     * @return Priority
151
     */
152
    public function getPriority(): ?Priority
153
    {
154
        return $this->priority;
155
    }
156
157
    /**
158
     * Set expiration
159
     *
160
     * @param Expiration $expiration
161
     *
162
     * @return Notification
163
     */
164
    public function withExpiration(Expiration $expiration = null): Notification
165
    {
166
        $cloned = clone $this;
167
168
        $cloned->expiration = $expiration;
169
170
        return $cloned;
171
    }
172
173
    /**
174
     * Get expiration
175
     *
176
     * @return Expiration
177
     */
178
    public function getExpiration(): ?Expiration
179
    {
180
        return $this->expiration;
181
    }
182
183
    /**
184
     * Set the collapse identifier
185
     *
186
     * @param CollapseId|null $collapseId
187
     *
188
     * @return Notification
189
     */
190
    public function withCollapseId(CollapseId $collapseId = null): Notification
191
    {
192
        $cloned = clone $this;
193
194
        $cloned->collapseId = $collapseId;
195
196
        return $cloned;
197
    }
198
199
    /**
200
     * Get the collapse identifier
201
     *
202
     * @return CollapseId|null
203
     */
204
    public function getCollapseId(): ?CollapseId
205
    {
206
        return $this->collapseId;
207
    }
208
    
209
    public function withPushType(PushType $pushType): Notification
210
    {
211
        $cloned = clone $this;
212
    
213
        $cloned->pushType = $pushType;
214
    
215
        return $cloned;
216
    }
217
    
218
    public function getPushType(): ?PushType
219
    {
220
        return $this->pushType;
221
    }
222
}
223