Completed
Push — master ( a73040...9c3b49 )
by Vladimir
05:44 queued 02:32
created

Enum::has()   A

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