for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Spatie\ValidationRules\Rules;
use Illuminate\Contracts\Validation\Rule;
use Illuminate\Support\Arr;
use League\ISO3166\ISO3166;
class CountryCode implements Rule
{
/** @var bool */
protected $required;
/** @var string */
protected $attribute;
public function __construct(bool $required = true)
$this->required = $required;
}
public function nullable(): self
$this->required = false;
return $this;
public function passes($attribute, $value): bool
$this->attribute = $attribute;
if (! $this->required && ($value === '0' || $value === 0 || $value === null)) {
return true;
$countries = Arr::pluck((new ISO3166())->all(), ISO3166::KEY_ALPHA2);
(new \League\ISO3166\ISO3166())->all()
array<integer,array>
object<Illuminate\Support\iterable>
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example:
function acceptsInteger($int) { } $x = '123'; // string "123" // Instead of acceptsInteger($x); // we recommend to use acceptsInteger((integer) $x);
return in_array($value, $countries, true);
public function message(): string
return __('validationRules::messages.country_code', [
'attribute' => $this->attribute,
]);
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: