Passed
Branch beta (1b8e35)
by Jon
07:16
created

ValidatesPrefix::message()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
1
<?php
2
3
namespace App\Rules;
4
5
use Illuminate\Contracts\Validation\Rule;
6
7
class ValidatesPrefix implements Rule
8
{
9
    /**
10
     * @var array
11
     */
12
    private $prefixes;
13
14
    /**
15
     * Create a new rule instance.
16
     *
17
     * @param array $prefixes
18
     */
19
    public function __construct(array $prefixes)
20
    {
21
        //
22
        $this->prefixes = $prefixes;
23
    }
24
25
    /**
26
     * Determine if the validation rule passes.
27
     *
28
     * @param  string  $attribute
29
     * @param  mixed  $value
30
     * @return bool
31
     */
32
    public function passes($attribute, $value): ?bool
33
    {
34
        return in_array($value, $this->prefixes);
35
    }
36
37
    /**
38
     * Get the validation error message.
39
     *
40
     * @return string
41
     */
42
    public function message(): string
43
    {
44
        return 'Uses an unregistered prefix.';
45
    }
46
}
47