Completed
Push — master ( 02f92d...9c9507 )
by Sebastian
15:38
created

Enum::allAsRegex()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 6
rs 9.4285
cc 1
eloc 4
nc 1
nop 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 allAsRegex() : string
24
    {
25
        return collect(static::values())->map(function ($value) {
26
            return "({$value})";
27
        })->implode('|');
28
    }
29
}
30