Model::verify()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2.1481

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 2
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 4
ccs 2
cts 3
cp 0.6667
crap 2.1481
rs 10
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