Priority::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 1

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 1
nop 1
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 2
rs 9.4285
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