Enum   A
last analyzed

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
rs 10
c 0
b 0
f 0

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 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