File tree Expand file tree Collapse file tree 7 files changed +74
-85
lines changed Expand file tree Collapse file tree 7 files changed +74
-85
lines changed Original file line number Diff line number Diff line change 11build
22composer.lock
33vendor
4- run.php
4+ run.php
5+ .DS_Store
6+ .phpunit.result.cache
Original file line number Diff line number Diff line change 3232 },
3333 "minimum-stability" : " stable" ,
3434 "require" : {
35- "illuminate/contracts" : " ^5.5|^6.0|^7.0|^8.0|^9.0|^ 10.0|^11.0|^12 .0" ,
36- "illuminate/support" : " ^5.5|^6.0|^7.0|^8.0|^9.0|^ 10.0|^11.0|^12 .0" ,
37- "php" : " ^7.0|^ 8.0"
35+ "illuminate/contracts" : " ^10.0|^11.0" ,
36+ "illuminate/support" : " ^10.0|^11.0" ,
37+ "php" : " ^8.0"
3838 },
3939 "require-dev" : {
40- "phpunit/phpunit" : " ^6.3|^9.0|^10.5|^11.5.3 " ,
40+ "phpunit/phpunit" : " ^6.3|^9.0|^10.5|^11.0|^12.0 " ,
4141 "orchestra/testbench" : " ^3.5|^5.0|^7.0|^9.0|^10.0"
4242 },
43- "suggest" : []
43+ "suggest" : {}
4444}
Original file line number Diff line number Diff line change 11<?php
22namespace LVR \Phone ;
33
4- use Illuminate \ Contracts \ Validation \ Rule ;
4+ use Closure ;
55
66class Digits extends Phone
77{
88 /**
9- * Determine if the validation rule passes.
10- *
11- * @param string $attribute
12- * @param mixed $value
13- *s
14- * @return bool
9+ * Validation error message
1510 */
16- public function passes ($ attribute , $ value )
17- {
18- return $ this ->isDigits ($ value );
19- }
11+ protected string $ message = ':attribute must be in digits only phone format ' ;
2012
2113 /**
22- * Get the validation error message .
14+ * Run the validation rule .
2315 *
24- * @return string
16+ * @param string $attribute
17+ * @param mixed $value
18+ * @param \Closure(string, ?string=): \Illuminate\Translation\PotentiallyTranslatedString $fail
19+ * @return void
2520 */
26- public function message ()
21+ public function validate ( string $ attribute , mixed $ value , Closure $ fail ): void
2722 {
28- return ':attribute must be in digits only phone format ' ;
23+ if (! $ this ->isDigits ($ value )) {
24+ $ fail ($ this ->message );
25+ }
2926 }
3027}
Original file line number Diff line number Diff line change 22
33namespace LVR \Phone ;
44
5+ use Closure ;
56
67class E123 extends Phone
78{
89 /**
9- * Determine if the validation rule passes.
10- *
11- * @param string $attribute
12- * @param mixed $value
13- *
14- * @return bool
10+ * Validation error message
1511 */
16- public function passes ($ attribute , $ value )
17- {
18- return $ this ->isE123 ($ value );
19- }
12+ protected string $ message = ':attribute must be in E.123 phone format ' ;
2013
2114 /**
22- * Get the validation error message .
15+ * Run the validation rule .
2316 *
24- * @return string
17+ * @param string $attribute
18+ * @param mixed $value
19+ * @param \Closure(string, ?string=): \Illuminate\Translation\PotentiallyTranslatedString $fail
20+ * @return void
2521 */
26- public function message ()
22+ public function validate ( string $ attribute , mixed $ value , Closure $ fail ): void
2723 {
28- return ':attribute must be in E.123 phone format ' ;
24+ if (! $ this ->isE123 ($ value )) {
25+ $ fail ($ this ->message );
26+ }
2927 }
30- }
28+ }
Original file line number Diff line number Diff line change 11<?php
22namespace LVR \Phone ;
33
4- use Illuminate \ Contracts \ Validation \ Rule ;
4+ use Closure ;
55
66class E164 extends Phone
77{
88 /**
9- * Determine if the validation rule passes.
10- *
11- * @param string $attribute
12- * @param mixed $value
13- *
14- * @return bool
9+ * Validation error message
1510 */
16- public function passes ($ attribute , $ value )
17- {
18- return $ this ->isE164 ($ value );
19- }
11+ protected string $ message = ':attribute must be in E.164 phone format ' ;
2012
2113 /**
22- * Get the validation error message .
14+ * Run the validation rule .
2315 *
24- * @return string
16+ * @param string $attribute
17+ * @param mixed $value
18+ * @param \Closure(string, ?string=): \Illuminate\Translation\PotentiallyTranslatedString $fail
19+ * @return void
2520 */
26- public function message ()
21+ public function validate ( string $ attribute , mixed $ value , Closure $ fail ): void
2722 {
28- return ':attribute must be in E.164 phone format ' ;
23+ if (! $ this ->isE164 ($ value )) {
24+ $ fail ($ this ->message );
25+ }
2926 }
30- }
27+ }
Original file line number Diff line number Diff line change 11<?php
22namespace LVR \Phone ;
33
4- use Illuminate \ Contracts \ Validation \ Rule ;
4+ use Closure ;
55
66class NANP extends Phone
77{
88 /**
9- * Determine if the validation rule passes.
10- *
11- * @param string $attribute
12- * @param mixed $value
13- *s
14- * @return bool
9+ * Validation error message
1510 */
16- public function passes ($ attribute , $ value )
17- {
18- return $ this ->isNANP ($ value );
19- }
11+ protected string $ message = ':attribute must be in the NANP phone format ' ;
2012
2113 /**
22- * Get the validation error message .
14+ * Run the validation rule .
2315 *
24- * @return string
16+ * @param string $attribute
17+ * @param mixed $value
18+ * @param \Closure(string, ?string=): \Illuminate\Translation\PotentiallyTranslatedString $fail
19+ * @return void
2520 */
26- public function message ()
21+ public function validate ( string $ attribute , mixed $ value , Closure $ fail ): void
2722 {
28- return ':attribute must be in the NANP phone format ' ;
23+ if (! $ this ->isNANP ($ value )) {
24+ $ fail ($ this ->message );
25+ }
2926 }
30- }
27+ }
Original file line number Diff line number Diff line change 11<?php
22namespace LVR \Phone ;
33
4- use Illuminate \Contracts \Validation \Rule ;
4+ use Closure ;
5+ use Illuminate \Contracts \Validation \ValidationRule ;
56
6- class Phone implements Rule
7+ class Phone implements ValidationRule
78{
89 /**
9- * Determine if the validation rule passes.
10- *
11- * @param string $attribute
12- * @param mixed $value
13- *
14- * @return bool
10+ * Validation error message
1511 */
16- public function passes ($ attribute , $ value )
17- {
18- return $ this ->isPhone ($ value );
19- }
12+ protected string $ message = 'Incorrect phone format for :attribute. ' ;
2013
2114 /**
22- * Get the validation error message .
15+ * Run the validation rule .
2316 *
24- * @return string
17+ * @param string $attribute
18+ * @param mixed $value
19+ * @param \Closure(string, ?string=): \Illuminate\Translation\PotentiallyTranslatedString $fail
20+ * @return void
2521 */
26- public function message ()
22+ public function validate ( string $ attribute , mixed $ value , Closure $ fail ): void
2723 {
28- return 'Incorrect phone format for :attribute. ' ;
24+ if (! $ this ->isPhone ($ value )) {
25+ $ fail ($ this ->message );
26+ }
2927 }
3028
3129 /**
@@ -90,4 +88,4 @@ protected function isNANP($value)
9088 $ conditions [] = preg_match ("/^(?:\+1|1)?\s?-?\(?\d{3}\)?(\s|-)?\d{3}-\d{4}$/i " , $ value ) > 0 ;
9189 return (bool ) array_product ($ conditions );
9290 }
93- }
91+ }
You can’t perform that action at this time.
0 commit comments