1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the MilioooMessageBundle package. |
5
|
|
|
* |
6
|
|
|
* (c) Michiel boeckaert <[email protected]> |
7
|
|
|
* This source file is subject to the MIT license that is bundled |
8
|
|
|
* with this source code in the file LICENSE. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Miliooo\Messaging\ValueObjects; |
12
|
|
|
|
13
|
|
|
use Miliooo\Messaging\Model\MessageMetaInterface; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Read Status value object. |
17
|
|
|
* |
18
|
|
|
* This value objects makes sure the read statuses are valid. A read status is valid if it's one of the |
19
|
|
|
* MessageMetaInterface class constants. |
20
|
|
|
* |
21
|
|
|
* @author Michiel Boeckaert <[email protected]> |
22
|
|
|
*/ |
23
|
|
|
class ReadStatus |
24
|
|
|
{ |
25
|
|
|
private $readStatus; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Constructor. |
29
|
|
|
* |
30
|
|
|
* @param integer $readStatus |
31
|
|
|
*/ |
32
|
|
|
public function __construct($readStatus) |
33
|
|
|
{ |
34
|
|
|
if ($this->isValidReadStatus($readStatus)) { |
35
|
|
|
$this->readStatus = $readStatus; |
36
|
|
|
} |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Returns the read status of a message |
41
|
|
|
* |
42
|
|
|
* @return integer The read status of a message |
43
|
|
|
*/ |
44
|
|
|
public function getReadStatus() |
45
|
|
|
{ |
46
|
|
|
return $this->readStatus; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Checks if the given read status is a valid read status. |
51
|
|
|
* |
52
|
|
|
* @param mixed $readStatus The read status we check |
53
|
|
|
* |
54
|
|
|
* @return true if the read status is valid. |
|
|
|
|
55
|
|
|
* |
56
|
|
|
* @throws \InvalidArgumentException If the read status is invalid. |
57
|
|
|
*/ |
58
|
|
|
protected function isValidReadStatus($readStatus) |
59
|
|
|
{ |
60
|
|
|
if (!is_integer($readStatus) || !in_array( |
61
|
|
|
$readStatus, |
62
|
|
|
[ |
63
|
|
|
MessageMetaInterface::READ_STATUS_NEVER_READ, |
64
|
|
|
MessageMetaInterface::READ_STATUS_MARKED_UNREAD, |
65
|
|
|
MessageMetaInterface::READ_STATUS_READ |
66
|
|
|
], |
67
|
|
|
true |
68
|
|
|
) |
69
|
|
|
) { |
70
|
|
|
throw new \InvalidArgumentException('Read status is not valid'); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
return true; |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.