Passed
Push — main ( 84e8a4...ccca22 )
by Andrey
03:59
created

Model::unavailable()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 1
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 3
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
    public static function verify(int $value): void
20
    {
21
        if (self::unavailable($value)) {
22
            throw new IncorrectModelKeyException($value);
23
        }
24
    }
25
26
    public static function available(): array
27
    {
28
        $class = new ReflectionClass(self::class);
29
30
        return array_values($class->getConstants());
31
    }
32
33
    protected static function unavailable(int $value): bool
34
    {
35
        return ! is_int($value) || ! in_array($value, self::available());
36
    }
37
}
38