Completed
Push — develop ( d56149...badf6b )
by Andrea Marco
05:00
created

Keys::map()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 24
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 14
nc 1
nop 0
dl 0
loc 24
ccs 13
cts 13
cp 1
crap 2
rs 9.7998
c 0
b 0
f 0
1
<?php
2
3
namespace Cerbero\LaravelEnum;
4
5
use Rexlabs\Enum\Enum;
6
use Illuminate\Support\Str;
7
8
/**
9
 * The Keys enum.
10
 *
11
 * @method static self BITWISE()
12
 * @method static self INT0()
13
 * @method static self INT1()
14
 * @method static self LOWER()
15
 */
16
class Keys extends Enum
17
{
18
    const BITWISE = 'bitwise';
19
    const INT0 = 'int0';
20
    const INT1 = 'int1';
21
    const LOWER = 'lower';
22
23
    /**
24
     * Retrieve a map of enum keys and values.
25
     *
26
     * @return array
27
     */
28 21
    public static function map() : array
29
    {
30
        return [
31
            static::BITWISE => function () {
32 6
                static $key;
33
34 6
                if (isset($key)) {
35 6
                    return $key *= 2;
36
                }
37
38 6
                return $key = 1;
39 21
            },
40
            static::INT0 => function () {
41 9
                static $key = 0;
42
43 9
                return $key++;
44 21
            },
45
            static::INT1 => function () {
46 3
                static $key = 1;
47
48 3
                return $key++;
49 21
            },
50
            static::LOWER => function (string $name) {
51 18
                return Str::lower($name);
52 21
            },
53
        ];
54
    }
55
}
56