Status   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Importance

Changes 0
Metric Value
wmc 8
lcom 2
cbo 0
dl 0
loc 57
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A fromString() 0 4 1
A getPossibleStatuses() 0 9 1
A active() 0 4 1
A blocked() 0 4 1
A isBlocked() 0 4 1
A __toString() 0 4 1
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(string $status)
21
    {
22
        if (!in_array($status, self::getPossibleStatuses())) {
23
            throw InvalidStatusException::withStatus($status);
24
        }
25
26
        $this->status = $status;
27
    }
28
29
    public static function fromString(string $status): self
30
    {
31
        return new self($status);
32
    }
33
34
    public static function getPossibleStatuses(): array
35
    {
36
        $statuses = [
37
            self::ACTIVE,
38
            self::BLOCKED,
39
        ];
40
41
        return array_combine($statuses, $statuses);
42
    }
43
44
    public static function active(): self
45
    {
46
        return new self(self::ACTIVE);
47
    }
48
49
    public static function blocked(): self
50
    {
51
        return new self(self::BLOCKED);
52
    }
53
54
    public function isBlocked(): bool
55
    {
56
        return $this->status === self::BLOCKED;
57
    }
58
59
    public function __toString(): string
60
    {
61
        return $this->status;
62
    }
63
}
64