These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Spatie\ValidationRules\Rules; |
||
4 | |||
5 | use League\ISO3166\ISO3166; |
||
6 | use Illuminate\Contracts\Validation\Rule; |
||
7 | |||
8 | class CountryCode implements Rule |
||
9 | { |
||
10 | /** @var bool */ |
||
11 | protected $required; |
||
12 | |||
13 | /** @var string */ |
||
14 | protected $attribute; |
||
15 | |||
16 | 24 | public function __construct(bool $required = true) |
|
17 | { |
||
18 | 24 | $this->required = $required; |
|
19 | 24 | } |
|
20 | |||
21 | 6 | public function nullable(): self |
|
22 | { |
||
23 | 6 | $this->required = false; |
|
24 | |||
25 | 6 | return $this; |
|
26 | } |
||
27 | |||
28 | 24 | public function passes($attribute, $value): bool |
|
29 | { |
||
30 | 24 | $this->attribute = $attribute; |
|
31 | |||
32 | 24 | if (! $this->required && ($value === '0' || $value === 0 || $value === null)) { |
|
33 | 6 | return true; |
|
34 | } |
||
35 | |||
36 | 24 | $countries = array_pluck((new ISO3166())->all(), ISO3166::KEY_ALPHA2); |
|
0 ignored issues
–
show
|
|||
37 | |||
38 | 24 | return in_array($value, $countries, true); |
|
39 | } |
||
40 | |||
41 | 12 | public function message(): string |
|
42 | { |
||
43 | 12 | return __('validationRules::messages.country_code', [ |
|
44 | 12 | 'attribute' => $this->attribute, |
|
45 | ]); |
||
46 | } |
||
47 | } |
||
48 |
This function has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.