Lint PHP code psr-12, add GH action
This commit is contained in:
@@ -3,25 +3,24 @@
|
||||
namespace App\Rules;
|
||||
|
||||
use Illuminate\Contracts\Validation\Rule;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class ValidPhoneInputRule implements Rule
|
||||
{
|
||||
|
||||
public ?int $reason = 0;
|
||||
|
||||
public function passes($attribute, $value)
|
||||
{
|
||||
if (!is_string($value) || !$value) {
|
||||
if (! is_string($value) || ! $value) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
if(ctype_alpha(substr($value, 0, 2))){ // First 2 will be country code
|
||||
if (ctype_alpha(substr($value, 0, 2))) { // First 2 will be country code
|
||||
$value = substr($value, 2);
|
||||
}
|
||||
$phoneUtil = \libphonenumber\PhoneNumberUtil::getInstance();
|
||||
$phone = $phoneUtil->parse($value);
|
||||
$this->reason = $phoneUtil->isPossibleNumberWithReason($phone);
|
||||
|
||||
return $this->reason === \libphonenumber\ValidationResult::IS_POSSIBLE;
|
||||
} catch (\Exception $e) {
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user