Test Setup Failed
Push — master ( ca3ca3...5e19b6 )
by Dennis
04:00
created

RegionNameRule   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 5
c 1
b 0
f 0
dl 0
loc 37
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A validate() 0 4 2
A message() 0 3 1
A passes() 0 3 1
1
<?php
2
namespace SimpleCMS\Region\Validation\Rule;
3
4
use SimpleCMS\Region\Validation\RegionName;
5
use Illuminate\Contracts\Validation\ValidationRule;
6
7
/**
8
 * 区划名称
9
 *
10
 * @author Dennis Lui <[email protected]>
11
 */
12
class RegionNameRule implements ValidationRule
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)
0 ignored issues
show
Unused Code introduced by
The parameter $attribute is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

36
    public function passes(/** @scrutinizer ignore-unused */ $attribute, $value)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
37
    {
38
        return (new RegionName($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
}