Completed
Push — master ( 883b54...c670aa )
by Freek
18:04 queued 03:10
created

Enum::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Spatie\ValidationRules\Rules;
4
5
use Illuminate\Contracts\Validation\Rule;
6
7
class Enum implements Rule
8
{
9
    /** @var array */
10
    protected $enumValues;
11
12
    public function __construct(string $enumClass)
13
    {
14
        $this->enumValues = $enumClass::toArray();
15
    }
16
17
    public function passes($attribute, $value)
18
    {
19
        return in_array($value, $this->enumValues);
20
    }
21
22
    public function message()
23
    {
24
        return 'This is not a valid value.';
25
    }
26
}
27