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

Enum   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 40
c 0
b 0
f 0
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A labels() 0 4 1
A label() 0 4 1
A constants() 0 4 1
A has() 0 4 1
A getKey() 0 4 1
A translations() 0 4 1
A translation() 0 4 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
}