Completed
Branch Version3 (6fba0e)
by Sam
01:26
created

Classes   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 0
dl 0
loc 52
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A isValid() 0 4 1
A getClassId() 0 8 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of Badcow DNS Library.
7
 *
8
 * (c) Samuel Williams <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Badcow\DNS;
15
16
class Classes
17
{
18
    const INTERNET = 'IN';
19
    const CSNET = 'CS';
20
    const CHAOS = 'CH';
21
    const HESIOD = 'HS';
22
23
    /**
24
     * @var array
25
     */
26
    public static $classes = [
27
        self::CHAOS => 'CHAOS',
28
        self::CSNET => 'CSNET',
29
        self::HESIOD => 'Hesiod',
30
        self::INTERNET => 'Internet',
31
    ];
32
33
    const CLASS_IDS = [
34
        self::CHAOS => 3,
35
        self::CSNET => 2,
36
        self::HESIOD => 4,
37
        self::INTERNET => 1,
38
    ];
39
40
    /**
41
     * Determine if a class is valid.
42
     *
43
     * @param string $class
44
     *
45
     * @return bool
46
     */
47 36
    public static function isValid(string $class): bool
48
    {
49 36
        return array_key_exists($class, self::$classes);
50
    }
51
52
    /**
53
     * @param string $className
54
     *
55
     * @return int
56
     *
57
     * @throws \InvalidArgumentException
58
     */
59 2
    public static function getClassId(string $className): int
60
    {
61 2
        if (!self::isValid($className)) {
62 1
            throw new \InvalidArgumentException(sprintf('Class "%s" is not a valid DNS class.', $className));
63
        }
64
65 1
        return self::CLASS_IDS[$className];
66
    }
67
}
68