Completed
Pull Request — master (#30)
by
unknown
02:47
created

Status::blocked()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace SumoCoders\FrameworkMultiUserBundle\ValueObject;
4
5
use SumoCoders\FrameworkMultiUserBundle\Exception\InvalidStatusException;
6
7
final class Status
8
{
9
    const ACTIVE = 'active';
10
    const BLOCKED = 'blocked';
11
12
    /** @var string */
13
    private $status;
14
15
    /**
16
     * @param string $status
17
     *
18
     * @throws InvalidStatusException
19
     */
20
    private function __construct($status)
21
    {
22
        if (!in_array($status, self::getPossibleStatuses())) {
23
            throw InvalidStatusException::withStatus($status);
24
        }
25
26
        $this->status = $status;
27
    }
28
29
    /**
30
     * @param string $status
31
     *
32
     * @return Status
33
     */
34
    public static function fromString($status)
35
    {
36
        return new self($status);
37
    }
38
39
    /**
40
     * @return array
41
     */
42
    public static function getPossibleStatuses()
43
    {
44
        $statuses = [
45
            self::ACTIVE,
46
            self::BLOCKED,
47
        ];
48
49
        return array_combine($statuses, $statuses);
50
    }
51
52
    /**
53
     * @return Status
54
     */
55
    public static function active()
56
    {
57
        return new self(self::ACTIVE);
58
    }
59
60
    /**
61
     * @return Status
62
     */
63
    public static function blocked()
64
    {
65
        return new self(self::BLOCKED);
66
    }
67
68
    /**
69
     * @return bool
70
     */
71
    public function isBlocked()
72
    {
73
        return $this->status === self::blocked();
74
    }
75
76
    /**
77
     * @return string
78
     */
79
    public function __toString()
80
    {
81
        return $this->status;
82
    }
83
}
84