ReadStatus   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 2
Bugs 1 Features 1
Metric Value
wmc 6
lcom 0
cbo 0
dl 0
loc 53
rs 10
c 2
b 1
f 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 2
A getReadStatus() 0 4 1
A isValidReadStatus() 0 17 3
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.
0 ignored issues
show
Documentation introduced by
Should the return type not be boolean?

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.

Loading history...
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