Status::__toString()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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