Model   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 88.89%

Importance

Changes 4
Bugs 1 Features 0
Metric Value
eloc 8
c 4
b 1
f 0
dl 0
loc 28
ccs 8
cts 9
cp 0.8889
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A available() 0 5 1
A unavailable() 0 3 2
A verify() 0 4 2
1
<?php
2
3
namespace Helldar\ShortUrl\Variables;
4
5
use Helldar\ShortUrl\Exceptions\IncorrectModelKeyException;
6
use ReflectionClass;
7
8
class Model
9
{
10
    public const PRIMARY_KEY = 1;
11
12
    public const UNIQUE_STRING = 2;
13
14
    /**
15
     * @param  int  $value
16
     *
17
     * @throws \Helldar\ShortUrl\Exceptions\IncorrectModelKeyException
18
     */
19 8
    public static function verify(int $value): void
20
    {
21 8
        if (self::unavailable($value)) {
22
            throw new IncorrectModelKeyException($value);
23
        }
24 8
    }
25
26 8
    public static function available(): array
27
    {
28 8
        $class = new ReflectionClass(self::class);
29
30 8
        return array_values($class->getConstants());
31
    }
32
33 8
    protected static function unavailable(int $value): bool
34
    {
35 8
        return ! is_int($value) || ! in_array($value, self::available());
36
    }
37
}
38