Skip to content

Commit b37935b

Browse files
milwad-devgithub-actions[bot]
authored andcommitted
Fix styling
1 parent eb5eae3 commit b37935b

File tree

5 files changed

+16
-16
lines changed

5 files changed

+16
-16
lines changed

config/laravel-validate.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@
88
'name' => 'base64',
99
'class' => ValidBase64::class,
1010
],
11-
]
11+
],
1212
];

src/Rules/ValidPhoneNumber.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Milwad\LaravelValidate\Rules;
44

5-
use Exception;
65
use Illuminate\Contracts\Validation\Rule;
76
use Milwad\LaravelValidate\Utils\CountryPhoneCallback;
87

@@ -11,6 +10,7 @@ class ValidPhoneNumber implements Rule
1110
public function __construct(protected ?string $code = null)
1211
{
1312
}
13+
1414
/**
1515
* Check phone number is valid.
1616
*
@@ -21,9 +21,11 @@ public function __construct(protected ?string $code = null)
2121
public function passes($attribute, $value)
2222
{
2323
if (is_string($this->code)) {
24-
$passes = (new CountryPhoneCallback($value, $this->code))->callPhoneValidator();
24+
$passes = (new CountryPhoneCallback($value, $this->code))->callPhoneValidator();
25+
2526
return collect($passes)->some(fn ($passe) => $passe);
2627
}
28+
2729
return preg_match('/^[\+]?[(]?[0-9]{3}[)]?[-\s\.]?[0-9]{3}[-\s\.]?[0-9]{4,6}$/', $value);
2830
}
2931

src/Utils/Country.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,4 +219,4 @@ class Country
219219
public const UNITED_KINGDOM = 'GB';
220220

221221
public const VIRGIN_ISLANDS_BRITISH = 'VG';
222-
}
222+
}

src/Utils/CountryPhoneCallback.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,14 @@ class CountryPhoneCallback
77
/**
88
* Create a new phone validator instance.
99
*
10-
* @param mixed $value The phone number to validate.
11-
* @param string $code The country codes to validate against. String can be separated by comma
12-
* @param string|null $attribute
10+
* @param mixed $value The phone number to validate.
11+
* @param string $code The country codes to validate against. String can be separated by comma
12+
* @param string|null $attribute
1313
*/
1414
public function __construct(protected $value, protected string $code, $attribute = null)
1515
{
1616
}
1717

18-
19-
2018
protected function validateBJ(): bool
2119
{
2220
return preg_match('/^(\+229|00229|229)?\d{8}$/', $this->value);
@@ -25,9 +23,9 @@ protected function validateBJ(): bool
2523
/**
2624
* Call the phone validator method for each country code and return the results.
2725
*
28-
* @throws \BadMethodCallException if the validator method for a country code does not exist.
29-
*
3026
* @return array An array of validation results, where each key is a country code and the value is either `true` or `false`.
27+
*
28+
* @throws \BadMethodCallException if the validator method for a country code does not exist.
3129
*/
3230
public function callPhoneValidator(): array
3331
{
@@ -38,7 +36,7 @@ public function callPhoneValidator(): array
3836
$codes = array_map('strtoupper', $codes);
3937

4038
foreach ($codes as $code) {
41-
$methodName = 'validate' . $code;
39+
$methodName = 'validate'.$code;
4240

4341
if (method_exists($this, $methodName)) {
4442
$results[$code] = $this->{$methodName}();

tests/Rules/ValidPhoneNumberTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ public function phone_number_is_valid()
2727
{
2828
$rules = [
2929
'phone_number' => [new ValidPhoneNumber()],
30-
'phone_bj' => [new ValidPhoneNumber(Country::BENIN)]
30+
'phone_bj' => [new ValidPhoneNumber(Country::BENIN)],
3131
];
32-
$data = ['phone_number' => '09366000000', 'phone_bj' => "+22997000000"];
32+
$data = ['phone_number' => '09366000000', 'phone_bj' => '+22997000000'];
3333
$passes = $this->app['validator']->make($data, $rules)->passes();
3434

3535
$this->assertTrue($passes);
@@ -46,11 +46,11 @@ public function phone_number_is_not_valid()
4646
{
4747
$rules = [
4848
'phone_number' => [new ValidPhoneNumber()],
49-
'phone_bj' => [new ValidPhoneNumber(Country::BENIN)]
49+
'phone_bj' => [new ValidPhoneNumber(Country::BENIN)],
5050
];
5151
$data = [
5252
'phone_number' => '123456789',
53-
'phone_bj' => "+22697000000"
53+
'phone_bj' => '+22697000000',
5454
];
5555
$passes = $this->app['validator']->make($data, $rules)->passes();
5656

0 commit comments

Comments
 (0)