Priority::__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 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
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 Priority
12
 * @package Simple\Queue
13
 */
14
class Priority
15
{
16
    public const VERY_LOW = -2;
17
18
    public const LOW = -1;
19
20
    public const DEFAULT = 0;
21
22
    public const HIGH = 1;
23
24
    public const VERY_HIGH = 2;
25
26
    /** @var int */
27
    private int $priority;
28
29
    /**
30
     * Priority constructor.
31
     * @param int $value
32
     */
33 45
    public function __construct(int $value)
34
    {
35 45
        if (in_array($value, self::getPriorities(), true) === false) {
36 1
            throw new InvalidArgumentException(sprintf('"%s" is not a valid message priority.', $value));
37
        }
38
39 44
        $this->priority = $value;
40 44
    }
41
42
    /**
43
     * @return string
44
     */
45 17
    public function __toString(): string
46
    {
47 17
        return (string)$this->priority;
48
    }
49
50
    /**
51
     * @return int
52
     */
53 5
    public function getValue(): int
54
    {
55 5
        return $this->priority;
56
    }
57
58
    /**
59
     * @return array
60
     */
61 45
    public static function getPriorities(): array
62
    {
63
        return [
64 45
            self::VERY_LOW,
65 45
            self::LOW,
66 45
            self::DEFAULT,
67 45
            self::HIGH,
68 45
            self::VERY_HIGH,
69
        ];
70
    }
71
}
72