Priority   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 17
c 1
b 0
f 1
dl 0
loc 55
ccs 15
cts 15
cp 1
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __toString() 0 3 1
A getPriorities() 0 8 1
A getValue() 0 3 1
A __construct() 0 7 2
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