Skip to content

Fix deprecated rule classes #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
build
composer.lock
vendor
run.php
run.php
.DS_Store
.phpunit.result.cache
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
@@ -32,13 +32,13 @@
},
"minimum-stability": "stable",
"require": {
"illuminate/contracts": "^5.5|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0",
"illuminate/support": "^5.5|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0",
"php": "^7.0|^8.0"
"illuminate/contracts": "^10.0|^11.0",
"illuminate/support": "^10.0|^11.0",
"php": "^8.0"
},
"require-dev": {
"phpunit/phpunit": "^6.3|^9.0|^10.5",
"orchestra/testbench": "^3.5|^5.0|^7.0|^9.0"
"phpunit/phpunit": "^6.3|^9.0|^10.5|^11.0|^12.0",
"orchestra/testbench": "^3.5|^5.0|^7.0|^9.0|^10.0"
},
"suggest": []
"suggest": {}
}
27 changes: 12 additions & 15 deletions src/Digits.php
Original file line number Diff line number Diff line change
@@ -1,30 +1,27 @@
<?php
namespace LVR\Phone;

use Illuminate\Contracts\Validation\Rule;
use Closure;

class Digits extends Phone
{
/**
* Determine if the validation rule passes.
*
* @param string $attribute
* @param mixed $value
*s
* @return bool
* Validation error message
*/
public function passes($attribute, $value)
{
return $this->isDigits($value);
}
protected string $message = ':attribute must be in digits only phone format';

/**
* Get the validation error message.
* Run the validation rule.
*
* @return string
* @param string $attribute
* @param mixed $value
* @param \Closure(string, ?string=): \Illuminate\Translation\PotentiallyTranslatedString $fail
* @return void
*/
public function message()
public function validate(string $attribute, mixed $value, Closure $fail): void
{
return ':attribute must be in digits only phone format';
if (! $this->isDigits($value)) {
$fail($this->message);
}
}
}
28 changes: 13 additions & 15 deletions src/E123.php
Original file line number Diff line number Diff line change
@@ -2,29 +2,27 @@

namespace LVR\Phone;

use Closure;

class E123 extends Phone
{
/**
* Determine if the validation rule passes.
*
* @param string $attribute
* @param mixed $value
*
* @return bool
* Validation error message
*/
public function passes($attribute, $value)
{
return $this->isE123($value);
}
protected string $message = ':attribute must be in E.123 phone format';

/**
* Get the validation error message.
* Run the validation rule.
*
* @return string
* @param string $attribute
* @param mixed $value
* @param \Closure(string, ?string=): \Illuminate\Translation\PotentiallyTranslatedString $fail
* @return void
*/
public function message()
public function validate(string $attribute, mixed $value, Closure $fail): void
{
return ':attribute must be in E.123 phone format';
if (! $this->isE123($value)) {
$fail($this->message);
}
}
}
}
29 changes: 13 additions & 16 deletions src/E164.php
Original file line number Diff line number Diff line change
@@ -1,30 +1,27 @@
<?php
namespace LVR\Phone;

use Illuminate\Contracts\Validation\Rule;
use Closure;

class E164 extends Phone
{
/**
* Determine if the validation rule passes.
*
* @param string $attribute
* @param mixed $value
*
* @return bool
* Validation error message
*/
public function passes($attribute, $value)
{
return $this->isE164($value);
}
protected string $message = ':attribute must be in E.164 phone format';

/**
* Get the validation error message.
* Run the validation rule.
*
* @return string
* @param string $attribute
* @param mixed $value
* @param \Closure(string, ?string=): \Illuminate\Translation\PotentiallyTranslatedString $fail
* @return void
*/
public function message()
public function validate(string $attribute, mixed $value, Closure $fail): void
{
return ':attribute must be in E.164 phone format';
if (! $this->isE164($value)) {
$fail($this->message);
}
}
}
}
29 changes: 13 additions & 16 deletions src/NANP.php
Original file line number Diff line number Diff line change
@@ -1,30 +1,27 @@
<?php
namespace LVR\Phone;

use Illuminate\Contracts\Validation\Rule;
use Closure;

class NANP extends Phone
{
/**
* Determine if the validation rule passes.
*
* @param string $attribute
* @param mixed $value
*s
* @return bool
* Validation error message
*/
public function passes($attribute, $value)
{
return $this->isNANP($value);
}
protected string $message = ':attribute must be in the NANP phone format';

/**
* Get the validation error message.
* Run the validation rule.
*
* @return string
* @param string $attribute
* @param mixed $value
* @param \Closure(string, ?string=): \Illuminate\Translation\PotentiallyTranslatedString $fail
* @return void
*/
public function message()
public function validate(string $attribute, mixed $value, Closure $fail): void
{
return ':attribute must be in the NANP phone format';
if (! $this->isNANP($value)) {
$fail($this->message);
}
}
}
}
32 changes: 15 additions & 17 deletions src/Phone.php
Original file line number Diff line number Diff line change
@@ -1,31 +1,29 @@
<?php
namespace LVR\Phone;

use Illuminate\Contracts\Validation\Rule;
use Closure;
use Illuminate\Contracts\Validation\ValidationRule;

class Phone implements Rule
class Phone implements ValidationRule
{
/**
* Determine if the validation rule passes.
*
* @param string $attribute
* @param mixed $value
*
* @return bool
* Validation error message
*/
public function passes($attribute, $value)
{
return $this->isPhone($value);
}
protected string $message = 'Incorrect phone format for :attribute.';

/**
* Get the validation error message.
* Run the validation rule.
*
* @return string
* @param string $attribute
* @param mixed $value
* @param \Closure(string, ?string=): \Illuminate\Translation\PotentiallyTranslatedString $fail
* @return void
*/
public function message()
public function validate(string $attribute, mixed $value, Closure $fail): void
{
return 'Incorrect phone format for :attribute.';
if (! $this->isPhone($value)) {
$fail($this->message);
}
}

/**
@@ -90,4 +88,4 @@ protected function isNANP($value)
$conditions[] = preg_match("/^(?:\+1|1)?\s?-?\(?\d{3}\)?(\s|-)?\d{3}-\d{4}$/i", $value) > 0;
return (bool) array_product($conditions);
}
}
}