Issues (73)

src/Rules/ValidLandlineNumber.php (1 issue)

1
<?php
2
3
namespace Milwad\LaravelValidate\Rules;
4
5
use Illuminate\Contracts\Validation\Rule;
6
use Milwad\LaravelValidate\Utils\CountryLandlineCallback;
7
8
class ValidLandlineNumber implements Rule
9
{
10
    public function __construct(protected ?string $code = null) {}
11
12
    /**
13
     * Check phone number is valid.
14
     */
15
    public function passes($attribute, $value): bool
16
    {
17
        if (is_string($this->code)) {
18
            $passes = CountryLandlineCallback::callLandlineValidator($this->code, $value);
19
20
            return collect($passes)->some(fn ($passe) => $passe);
21
        }
22
23
        return preg_match('/^(?:\+|00)(?:[1-9]\d{0,2})(?:[ .\-]?\(?\d+\)?)+$/', $value);
0 ignored issues
show
Bug Best Practice introduced by
The expression return preg_match('/^(?:...\(?\d+\)?)+$/', $value) returns the type integer which is incompatible with the type-hinted return boolean.
Loading history...
24
    }
25
26
    /**
27
     * Get the validation error message.
28
     */
29
    public function message(): string
30
    {
31
        return __('validate.landline-number');
32
    }
33
}
34