Enum::label()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AcquiroPay\Contracts;
6
7
use AcquiroPay\Enums\Language;
8
use Illuminate\Support\Collection;
9
10
abstract class Enum
11
{
12
    protected const LABELS = [];
13
    protected const TRANSLATIONS = [];
14
15
    public static function labels(): Collection
16
    {
17
        return collect(static::LABELS);
18
    }
19
20
    public static function label($key, $default = null)
21
    {
22
        return static::labels()->get($key, $default);
23
    }
24
25
    public static function constants(): Collection
26
    {
27
        return static::labels()->keys();
28
    }
29
30
    public static function has($key): bool
31
    {
32
        return static::labels()->has($key);
33
    }
34
35
    public static function getKey(string $label): int
36
    {
37
        return (int) array_search($label, static::LABELS, true);
38
    }
39
40
    public static function translations(): Collection
41
    {
42
        return collect(static::TRANSLATIONS);
43
    }
44
45
    public static function translation(string $language = Language::RUSSIAN)
46
    {
47
        return static::translations()->get($language);
48
    }
49
}
50