Priority::toInt()   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 Werkspot\MessageBus\MessageQueue;
4
5
use Werkspot\MessageBus\Message\InvalidPriorityException;
6
7
final class Priority
8
{
9
    const LOWEST = 1;
10
    const LOW = 3;
11
    const NORMAL = 5;
12
    const HIGH = 7;
13
    const URGENT = 9;
14
15
    /**
16
     * @var int
17
     */
18
    private $value;
19
20 17
    public function __construct(int $priority)
21
    {
22 17
        if (!$this->isValid($priority)) {
23 4
            throw new InvalidPriorityException("Invalid priority: {$priority}.");
24
        }
25
26 13
        $this->value = $priority;
27 13
    }
28
29 8
    public function toInt(): int
30
    {
31 8
        return $this->value;
32
    }
33
34 17
    private function isValid(int $priority): bool
35
    {
36 17
        return self::LOWEST <= $priority && $priority <= self::URGENT;
37
    }
38
}
39