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

RegionAreaRule   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
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 38
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A message() 0 3 1
A validate() 0 4 2
A passes() 0 3 1
1
<?php
2
namespace SimpleCMS\Region\Validation\Rule;
3
4
use SimpleCMS\Region\Validation\RegionArea;
5
use Illuminate\Contracts\Validation\ValidationRule;
6
7
/**
8
 * 区号
9
 *
10
 * @author Dennis Lui <[email protected]>
11
 */
12
class RegionAreaRule implements ValidationRule
13
{
14
15
    /**
16
     * Run the validation rule.
17
     *
18
     * @param  string  $attribute
19
     * @param  mixed  $value
20
     * @param  \Closure(string): \Illuminate\Translation\PotentiallyTranslatedString  $fail
21
     * @return void
22
     */
23
    public function validate(string $attribute, mixed $value, \Closure $fail): void
24
    {
25
        if (!$this->passes($attribute, $value)) {
26
            $fail($this->message());
27
        }
28
    }
29
30
    /**
31
     * Determine if the validation rule passes.
32
     *
33
     * @param  string  $attribute
34
     * @param  mixed  $value
35
     * @return bool
36
     */
37
    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

37
    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...
38
    {
39
        return (new RegionArea($value))->isValid();
40
    }
41
42
    /**
43
     * Get the validation error message.
44
     *
45
     * @return string|array
46
     */
47
    public function message()
48
    {
49
        return 'The :attribute is incorrect.';
50
    }
51
}