ThreadStatus::isValidThreadStatus()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 8
nc 2
nop 1
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\ThreadMetaInterface;
14
15
/**
16
 * Thread Status value object.
17
 *
18
 * This value objects makes sure the thread statuses are valid. A thread status is valid if it's one of the
19
 * ThreadMetaInterface class constants.
20
 *
21
 * @author Michiel Boeckaert <[email protected]>
22
 */
23
24
class ThreadStatus
25
{
26
    /**
27
     * @var integer The thread status integer
28
     */
29
    private $threadStatus;
30
31
    /**
32
     * Constructor.
33
     *
34
     * @param integer $threadStatus
35
     */
36
    public function __construct($threadStatus)
37
    {
38
        if ($this->isValidThreadStatus($threadStatus)) {
39
            $this->threadStatus = $threadStatus;
40
        }
41
    }
42
43
    /**
44
     * Returns the thread status value.
45
     *
46
     * @return integer The thread status integer value
47
     */
48
    public function getThreadStatus()
49
    {
50
        return $this->threadStatus;
51
    }
52
53
    /**
54
     * Checks if the given thread status is valid.
55
     *
56
     * @param integer $threadStatus One of the thread status constants
57
     *
58
     * @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...
59
     *
60
     * @throws \InvalidArgumentException If the read status is invalid.
61
     */
62
    private function isValidThreadStatus($threadStatus)
63
    {
64
        if (!is_integer($threadStatus) || !in_array(
65
            $threadStatus,
66
            [
67
            ThreadMetaInterface::STATUS_ACTIVE,
68
            ThreadMetaInterface::STATUS_ARCHIVED
69
            ],
70
            true
71
            )
72
        ) {
73
            throw new \InvalidArgumentException('Invalid thread status');
74
        }
75
76
        return true;
77
    }
78
}
79