JobStatus::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Queue\Enum;
6
7
use Yiisoft\Queue\Exception\InvalidStatusException;
8
9
class JobStatus
10
{
11
    /** @psalm-suppress MissingClassConstType */
12
    final public const WAITING = 1;
13
    /** @psalm-suppress MissingClassConstType */
14
    final public const RESERVED = 2;
15
    /** @psalm-suppress MissingClassConstType */
16
    final public const DONE = 3;
17
18
    protected int $status;
19
20 9
    final protected function __construct(int $status)
21
    {
22 9
        if (!in_array($status, $this->available(), true)) {
23 1
            throw new InvalidStatusException($status);
24
        }
25
26 8
        $this->status = $status;
27
    }
28
29 9
    protected function available(): array
30
    {
31 9
        return [self::WAITING, self::RESERVED, self::DONE];
32
    }
33
34 3
    public static function waiting(): self
35
    {
36 3
        return new static(self::WAITING);
37
    }
38
39 1
    public static function reserved(): self
40
    {
41 1
        return new static(self::RESERVED);
42
    }
43
44 4
    public static function done(): self
45
    {
46 4
        return new static(self::DONE);
47
    }
48
49 4
    public function isWaiting(): bool
50
    {
51 4
        return $this->status === self::WAITING;
52
    }
53
54 3
    public function isReserved(): bool
55
    {
56 3
        return $this->status === self::RESERVED;
57
    }
58
59 5
    public function isDone(): bool
60
    {
61 5
        return $this->status === self::DONE;
62
    }
63
}
64