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

Enum   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3
Metric Value
wmc 4
lcom 0
cbo 3
dl 0
loc 23
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A equals() 0 8 2
A doesntEqual() 0 4 1
A allAsRegex() 0 6 1
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