Completed
Push — master ( cd7556...faf69c )
by Sebastian
04:23
created

Enum::toCollection()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Foundation\Models\Enums;
4
5
use MyCLabs\Enum\Enum as BaseEnum;
6
7
abstract class Enum extends BaseEnum
8
{
9
    public function equals(Enum $enum) : bool
10
    {
11
        if (!$enum instanceof $this) {
12
            throw new EnumTypesDontMatch();
13
        }
14
15
        return $this->getValue() === $enum->getValue();
16
    }
17
18
    public function doesntEqual(Enum $enum) : bool
19
    {
20
        return !$this->equals($enum);
21
    }
22
    
23
    public static function toCollection(): Collection
24
    {
25
        return collect(static::toArray());
26
    }
27
28
    public static function allAsRegex() : string
29
    {
30
        return collect(static::values())->map(function ($value) {
31
            return "({$value})";
32
        })->implode('|');
33
    }
34
}
35