Passed
Push — master ( abbd29...fab7f5 )
by Dennis
07:07 queued 03:54
created

BankCodeRule::validate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 2
c 1
b 0
f 0
nc 2
nop 3
dl 0
loc 4
rs 10
1
<?php
2
namespace SimpleCMS\Bank\Validation\Rule;
3
4
use Illuminate\Contracts\Validation\Rule;
5
use SimpleCMS\Bank\Validation\BankCode;
6
7
/**
8
 * 银行代码
9
 *
10
 * @author Dennis Lui <[email protected]>
11
 */
12
class BankCodeRule implements Rule
13
{
14
    /**
15
     * Run the validation rule.
16
     *
17
     * @param  string  $attribute
18
     * @param  mixed  $value
19
     * @param  \Closure(string): \Illuminate\Translation\PotentiallyTranslatedString  $fail
20
     * @return void
21
     */
22
    public function validate(string $attribute, mixed $value, \Closure $fail): void
23
    {
24
        if (!$this->passes($attribute, $value)) {
25
            $fail($this->message());
26
        }
27
    }
28
29
    /**
30
     * Determine if the validation rule passes.
31
     *
32
     * @param  string  $attribute
33
     * @param  mixed  $value
34
     * @return bool
35
     */
36
    public function passes($attribute, $value)
37
    {
38
        return (new BankCode($value))->isValid();
39
    }
40
41
    /**
42
     * Get the validation error message.
43
     *
44
     * @return string|array
45
     */
46
    public function message()
47
    {
48
        return 'The :attribute is incorrect.';
49
    }
50
}