1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Push notification services abstraction (http://github.com/juliangut/tify) |
4
|
|
|
* |
5
|
|
|
* @link https://github.com/juliangut/tify for the canonical source repository |
6
|
|
|
* |
7
|
|
|
* @license https://github.com/juliangut/tify/blob/master/LICENSE |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Jgut\Tify; |
11
|
|
|
|
12
|
|
|
class Result |
13
|
|
|
{ |
14
|
|
|
const STATUS_SUCCESS = 0; |
15
|
|
|
const STATUS_ERROR = 1; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Device token. |
19
|
|
|
* |
20
|
|
|
* @var string |
21
|
|
|
*/ |
22
|
|
|
protected $token; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Result time. |
26
|
|
|
* |
27
|
|
|
* @var \DateTime |
28
|
|
|
*/ |
29
|
|
|
protected $date; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Result status. |
33
|
|
|
* |
34
|
|
|
* @var int |
35
|
|
|
*/ |
36
|
|
|
protected $status; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Result status message. |
40
|
|
|
* |
41
|
|
|
* @var string |
42
|
|
|
*/ |
43
|
|
|
protected $statusMessage; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @param string $token |
47
|
|
|
* @param \DateTime $date |
|
|
|
|
48
|
|
|
* @param bool $status |
|
|
|
|
49
|
|
|
* @param string $statusMessage |
50
|
|
|
*/ |
51
|
|
|
public function __construct($token, \DateTime $date = null, $status = self::STATUS_SUCCESS, $statusMessage = '') |
52
|
|
|
{ |
53
|
|
|
$this->token = $token; |
54
|
|
|
|
55
|
|
|
if ($date !== null) { |
56
|
|
|
$date = new \DateTime; |
57
|
|
|
} |
58
|
|
|
$this->setDate($date); |
|
|
|
|
59
|
|
|
|
60
|
|
|
$this->setStatus($status); |
61
|
|
|
$this->setStatusMessage($statusMessage); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Retrieve result device token. |
66
|
|
|
* |
67
|
|
|
* @return string |
68
|
|
|
*/ |
69
|
|
|
public function getToken() |
70
|
|
|
{ |
71
|
|
|
return $this->token; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Set result device token. |
76
|
|
|
* |
77
|
|
|
* @param string $token |
78
|
|
|
*/ |
79
|
|
|
public function setToken($token) |
80
|
|
|
{ |
81
|
|
|
$this->token = trim($token); |
82
|
|
|
|
83
|
|
|
return $this; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Retrieve result time. |
88
|
|
|
* |
89
|
|
|
* @return \DateTime |
90
|
|
|
*/ |
91
|
|
|
public function getDate() |
92
|
|
|
{ |
93
|
|
|
return $this->date; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Set result time. |
98
|
|
|
* |
99
|
|
|
* @param \DateTime $date |
100
|
|
|
*/ |
101
|
|
|
public function setDate(\DateTime $date) |
102
|
|
|
{ |
103
|
|
|
$this->date = clone $date; |
104
|
|
|
|
105
|
|
|
return $this; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Retrieve result status. |
110
|
|
|
* |
111
|
|
|
* @return int |
112
|
|
|
*/ |
113
|
|
|
public function getStatus() |
114
|
|
|
{ |
115
|
|
|
return $this->status; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Check successfull status. |
120
|
|
|
* |
121
|
|
|
* @return bool |
122
|
|
|
*/ |
123
|
|
|
public function isSuccess() |
124
|
|
|
{ |
125
|
|
|
return $this->status === static::STATUS_SUCCESS; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* Check errored status. |
130
|
|
|
* |
131
|
|
|
* @return bool |
132
|
|
|
*/ |
133
|
|
|
public function isError() |
134
|
|
|
{ |
135
|
|
|
return $this->status === static::STATUS_ERROR; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* Set result status. |
140
|
|
|
* |
141
|
|
|
* @param int $status |
142
|
|
|
*/ |
143
|
|
|
public function setStatus($status) |
144
|
|
|
{ |
145
|
|
|
if (!is_int($status) || !in_array($status, [static::STATUS_SUCCESS, static::STATUS_ERROR])) { |
146
|
|
|
throw new \InvalidArgumentException(sprintf('"%s" is not a valid status', $status)); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
$this->status = $status; |
150
|
|
|
|
151
|
|
|
return $this; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* Retrieve result status message. |
156
|
|
|
* |
157
|
|
|
* @return string |
158
|
|
|
*/ |
159
|
|
|
public function getStatusMessage() |
160
|
|
|
{ |
161
|
|
|
return $this->statusMessage; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* Check successfull status message. |
166
|
|
|
* |
167
|
|
|
* @return string |
|
|
|
|
168
|
|
|
*/ |
169
|
|
|
public function setStatusMessage($statusMessage) |
170
|
|
|
{ |
171
|
|
|
$this->statusMessage = trim($statusMessage); |
172
|
|
|
|
173
|
|
|
return $this; |
174
|
|
|
} |
175
|
|
|
} |
176
|
|
|
|
This check looks for
@param
annotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.