Priority   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 30
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A toInt() 0 3 1
A __construct() 0 7 2
A isValid() 0 3 2
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