Completed
Push — master ( b2c31d...142309 )
by Vitaliy
01:49
created

Notification::__construct()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 11
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.2
c 0
b 0
f 0
cc 4
eloc 9
nc 8
nop 4
1
<?php
2
3
/*
4
 * This file is part of the AppleApnPush package
5
 *
6
 * (c) Vitaliy Zhuk <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code
10
 */
11
12
namespace Apple\ApnPush\Model;
13
14
/**
15
 * Send this notification to device.
16
 */
17
class Notification
18
{
19
    /**
20
     * @var Payload
21
     */
22
    private $payload;
23
24
    /**
25
     * @var ApnId
26
     */
27
    private $id;
28
29
    /**
30
     * @var Priority
31
     */
32
    private $priority;
33
34
    /**
35
     * @var Expiration
36
     */
37
    private $expiration;
38
39
    /**
40
     * Constructor.
41
     *
42
     * @param Payload         $payload
43
     * @param ApnId|null      $id
44
     * @param Priority|null   $priority
45
     * @param Expiration|null $expiration
46
     */
47
    public function __construct(
48
        Payload $payload,
49
        ApnId $id = null,
50
        Priority $priority = null,
51
        Expiration $expiration = null
52
    ) {
53
        $this->payload = $payload;
54
        $this->priority = $priority ?: Priority::fromNull();
55
        $this->id = $id ?: ApnId::fromNull();
56
        $this->expiration = $expiration ?: Expiration::fromNull();
57
    }
58
59
    /**
60
     * Set payload
61
     *
62
     * @param Payload $payload
63
     *
64
     * @return Notification
65
     */
66
    public function withPayload(Payload $payload)
67
    {
68
        $cloned = clone $this;
69
70
        $cloned->payload = $payload;
71
72
        return $cloned;
73
    }
74
75
    /**
76
     * Get payload
77
     *
78
     * @return Payload
79
     */
80
    public function getPayload()
81
    {
82
        return $this->payload;
83
    }
84
85
    /**
86
     * Set apn identifier
87
     *
88
     * @param ApnId $apnId
89
     *
90
     * @return Notification
91
     */
92
    public function withId(ApnId $apnId) : Notification
93
    {
94
        $cloned = clone $this;
95
96
        $cloned->id = $apnId;
97
98
        return $cloned;
99
    }
100
101
    /**
102
     * Get identifier of notification
103
     *
104
     * @return ApnId
105
     */
106
    public function getId() : ApnId
107
    {
108
        return $this->id;
109
    }
110
111
    /**
112
     * Set priority
113
     *
114
     * @param Priority $priority
115
     *
116
     * @return Notification
117
     */
118
    public function withPriority(Priority $priority) : Notification
119
    {
120
        $cloned = clone $this;
121
122
        $cloned->priority = $priority;
123
124
        return $cloned;
125
    }
126
127
    /**
128
     * Get priority
129
     *
130
     * @return Priority
131
     */
132
    public function getPriority() : Priority
133
    {
134
        return $this->priority;
135
    }
136
137
    /**
138
     * Set expiration
139
     *
140
     * @param Expiration $expiration
141
     *
142
     * @return Notification
143
     */
144
    public function withExpiration(Expiration $expiration) : Notification
145
    {
146
        $cloned = clone $this;
147
148
        $cloned->expiration = $expiration;
149
150
        return $cloned;
151
    }
152
153
    /**
154
     * Get expiration
155
     *
156
     * @return Expiration
157
     */
158
    public function getExpiration() : Expiration
159
    {
160
        return $this->expiration;
161
    }
162
}
163