Status   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Test Coverage

Coverage 85.71%

Importance

Changes 0
Metric Value
dl 0
loc 57
ccs 12
cts 14
cp 0.8571
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A listStatus() 0 7 1
A __toString() 0 3 1
A __construct() 0 7 2
A getValue() 0 3 1
1
<?php
2
3
namespace JobQueue\Domain\Task;
4
5
final class Status
6
{
7
    const WAITING  = 'waiting',
8
          RUNNING  = 'running',
9
          FINISHED = 'finished',
10
          FAILED   = 'failed';
11
12
    /**
13
     *
14
     * @var
15
     */
16
    private $value;
17
18
    /**
19
     *
20
     * @param $value
21
     * @throws \Exception
22
     */
23 31
    public function __construct($value)
24
    {
25 31
        if (!in_array($value, self::listStatus(), true)) {
26 1
            throw new \RuntimeException(sprintf('Status "%s" does not exists', $value));
27
        }
28
29 30
        $this->value = $value;
30 30
    }
31
32
    /**
33
     *
34
     * @return mixed
35
     */
36
    public function getValue()
37
    {
38
        return $this->value;
39
    }
40
41
    /**
42
     *
43
     * @return array
44
     */
45 32
    public static function listStatus(): array
46
    {
47
        return [
48 32
            self::WAITING,
49 32
            self::RUNNING,
50 32
            self::FINISHED,
51 32
            self::FAILED,
52
        ];
53
    }
54
55
    /**
56
     *
57
     * @return mixed
58
     */
59 21
    public function __toString()
60
    {
61 21
        return $this->value;
62
    }
63
}
64