HasNames   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 38
ccs 19
cts 19
cp 1
rs 10
wmc 7

5 Methods

Rating   Name   Duplication   Size   Complexity  
A transFileName() 0 3 1
A formattedOptions() 0 11 2
A transKey() 0 3 1
A name() 0 3 1
A options() 0 8 2
1
<?php
2
3
namespace ThinKit\Enums;
4
5
use Illuminate\Support\Str;
6
7
trait HasNames
8
{
9 3
    public function name(): string
10
    {
11 3
        return trans("{$this->transFileName()}.{$this->transKey()}.{$this->value}");
12
    }
13
14 4
    public function transFileName(): string
15
    {
16 4
        return config('thinkit.enums.trans_file_name');
17
    }
18
19 4
    public function transKey(): string
20
    {
21 4
        return Str::snake(class_basename(static::class));
22
    }
23
24 2
    public static function options(): array
25
    {
26 2
        $data = [];
27 2
        foreach (static::cases() as $case) {
28 2
            $data[$case->value] = $case->name();
29
        }
30
31 2
        return $data;
32
    }
33
34 1
    public static function formattedOptions(): array
35
    {
36 1
        $data = [];
37 1
        foreach (static::options() as $value => $label) {
38 1
            $data[] = [
39 1
                config('thinkit.enums.formatted_options_key.value') => $value,
40 1
                config('thinkit.enums.formatted_options_key.label') => $label,
41 1
            ];
42
        }
43
44 1
        return $data;
45
    }
46
}
47