AbstractDictionary::getValues()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PrettyBx\Support\Base;
6
7
abstract class AbstractDictionary
8
{
9
    abstract public static function getItems(): array;
10
11
    /**
12
     * Возвращает элемент списка
13
     *
14
     * @access  public static
15
     * @param   string  $code
16
     * @return  string
17
     */
18
    public static function getItem(string $code): string
19
    {
20
        if (!array_key_exists($code, static::getItems())) {
21
            throw new \InvalidArgumentException('Запрошенный элемент ' . $code . ' отсутствует в словаре ' . __CLASS__);
22
        }
23
24
        return static::getItems()[$code];
25
    }
26
27
    public static function getKeyByValue(string $value)
28
    {
29
        return array_search($value, static::getItems());
30
    }
31
32
    /**
33
     * Возвращает коды существующих элементов словаря
34
     *
35
     * @access  public static
36
     * @return  array
37
     */
38
    public static function getCodes(): array
39
    {
40
        return array_keys(static::getItems());
41
    }
42
43
    /**
44
     * Возвращает массив значений словаря
45
     *
46
     * @access  public static
47
     * @return  array
48
     */
49
    public static function getValues(): array
50
    {
51
        return array_values(static::getItems());
52
    }
53
}
54