Status::getStatuses()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 2
Metric Value
cc 1
eloc 6
c 2
b 0
f 2
nc 1
nop 0
dl 0
loc 8
ccs 6
cts 6
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Simple\Queue;
6
7
use function in_array;
8
use InvalidArgumentException;
9
10
/**
11
 * Class Status
12
 * @package Simple\Queue
13
 */
14
class Status
15
{
16
    /**
17
     * Set for a new message
18
     */
19
    public const NEW = 'NEW';
20
21
    /**
22
     * Set for a message that is being processed
23
     */
24
    public const IN_PROCESS = 'IN_PROCESS';
25
26
    /**
27
     * Set for a message for which an error occurred
28
     */
29
    public const FAILURE = 'FAILURE';
30
31
    /**
32
     * Set for a message to be redelivered to the queue
33
     */
34
    public const REDELIVERED = 'REDELIVERED';
35
36
    /**
37
     * Set for a message if there is no processor or job
38
     */
39
    public const UNDEFINED_HANDLER = 'UNDEFINED_HANDLER';
40
41
    /** @var string */
42
    private string $status;
43
44
    /**
45
     * Status constructor.
46
     * @param string $value
47
     */
48 44
    public function __construct(string $value)
49
    {
50 44
        if (in_array($value, self::getStatuses(), true) === false) {
51 1
            throw new InvalidArgumentException(sprintf('"%s" is not a valid message status.', $value));
52
        }
53
54 43
        $this->status = $value;
55 43
    }
56
57
    /**
58
     * @return string
59
     */
60 20
    public function __toString(): string
61
    {
62 20
        return $this->status;
63
    }
64
65
    /**
66
     * @return string
67
     */
68 4
    public function getValue(): string
69
    {
70 4
        return $this->status;
71
    }
72
73
    /**
74
     * @return array
75
     */
76 44
    public static function getStatuses(): array
77
    {
78
        return [
79 44
            self::NEW,
80 44
            self::IN_PROCESS,
81 44
            self::FAILURE,
82 44
            self::REDELIVERED,
83 44
            self::UNDEFINED_HANDLER,
84
        ];
85
    }
86
}
87