Skip to content

Commit 96b478c

Browse files
committed
refactor rules
1 parent 27ce3cc commit 96b478c

39 files changed

+88
-322
lines changed

src/Rules/ValidBase64.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,16 @@ class ValidBase64 implements Rule
88
{
99
/**
1010
* Check base64.
11-
*
12-
* @param string $attribute
13-
* @param mixed $value
14-
* @return bool
1511
*/
16-
public function passes($attribute, $value)
12+
public function passes($attribute, $value): bool
1713
{
1814
return base64_encode(base64_decode($value, true)) === $value;
1915
}
2016

2117
/**
2218
* Get the validation error message.
23-
*
24-
* @return string
2519
*/
26-
public function message()
20+
public function message(): string
2721
{
2822
return __('validate.base64');
2923
}

src/Rules/ValidBitcoinAddress.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,17 @@
77
class ValidBitcoinAddress implements Rule
88
{
99
/**
10-
* Check bitcoin address.
11-
*
12-
* @param string $attribute
13-
* @param mixed $value
14-
* @return bool
10+
* Check bitcoin address is valid.
1511
*/
16-
public function passes($attribute, $value)
12+
public function passes($attribute, $value): bool
1713
{
1814
return preg_match('/^(?:bc1|[13])[a-zA-HJ-NP-Z0-9]{25,39}$/', $value);
1915
}
2016

2117
/**
2218
* Get the validation error message.
23-
*
24-
* @return string
2519
*/
26-
public function message()
20+
public function message(): string
2721
{
2822
return __('validate.bitcoin-address');
2923
}

src/Rules/ValidCamelCase.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,16 @@ class ValidCamelCase implements Rule
88
{
99
/**
1010
* Check value is camel case.
11-
*
12-
* @param string $attribute
13-
* @param mixed $value
14-
* @return bool
1511
*/
16-
public function passes($attribute, $value)
12+
public function passes($attribute, $value): bool
1713
{
1814
return preg_match('/^(?:\p{Lu}?\p{Ll}+)(?:\p{Lu}\p{Ll}+)*$/u', $value);
1915
}
2016

2117
/**
2218
* Get the validation error message.
23-
*
24-
* @return string
2519
*/
26-
public function message()
20+
public function message(): string
2721
{
2822
return __('validate.camel-case');
2923
}

src/Rules/ValidCapitalCharWithNumber.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,16 @@ class ValidCapitalCharWithNumber implements Rule
88
{
99
/**
1010
* Check all words are capital & with hyphen & number.
11-
*
12-
* @param string $attribute
13-
* @param mixed $value
14-
* @return bool
1511
*/
16-
public function passes($attribute, $value)
12+
public function passes($attribute, $value): bool
1713
{
1814
return preg_match('/[A-Z]{2,}-\d+/', $value);
1915
}
2016

2117
/**
2218
* Get the validation error message.
23-
*
24-
* @return string
2519
*/
26-
public function message()
20+
public function message(): string
2721
{
2822
return __('validate.capital-char-with-number');
2923
}

src/Rules/ValidCarNumber.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,16 @@ class ValidCarNumber implements Rule
88
{
99
/**
1010
* Check car number is valid.
11-
*
12-
* @param string $attribute
13-
* @param mixed $value
14-
* @return bool
1511
*/
16-
public function passes($attribute, $value)
12+
public function passes($attribute, $value): bool
1713
{
1814
return preg_match('/^[A-Z]{2}[0-9]{2}[A-Z]{2}[0-9]{4}$/', $value);
1915
}
2016

2117
/**
2218
* Get the validation error message.
23-
*
24-
* @return string
2519
*/
26-
public function message()
20+
public function message(): string
2721
{
2822
return __('validate.car-number');
2923
}

src/Rules/ValidCartNumberIran.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,8 @@ class ValidCartNumberIran implements Rule
88
{
99
/**
1010
* Check cart number is valid.
11-
*
12-
* @param string $attribute
13-
* @param mixed $value
14-
* @return bool
1511
*/
16-
public function passes($attribute, $value)
12+
public function passes($attribute, $value): bool
1713
{
1814
$cardToArr = str_split($value);
1915
$cardTotal = 0;
@@ -31,10 +27,8 @@ public function passes($attribute, $value)
3127

3228
/**
3329
* Get the validation error message.
34-
*
35-
* @return string
3630
*/
37-
public function message()
31+
public function message(): string
3832
{
3933
return __('validate.cart-number-iran');
4034
}

src/Rules/ValidCreditCard.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,8 @@ class ValidCreditCard implements Rule
88
{
99
/**
1010
* Check if the credit card number is valid using the Luhn algorithm.
11-
*
12-
* @param string $attribute
13-
* @param mixed $value
14-
* @return bool
1511
*/
16-
public function passes($attribute, $value)
12+
public function passes($attribute, $value): bool
1713
{
1814
$value = preg_replace('/\D/', '', $value);
1915

@@ -37,10 +33,8 @@ public function passes($attribute, $value)
3733

3834
/**
3935
* Get the validation error message.
40-
*
41-
* @return string
4236
*/
43-
public function message()
37+
public function message(): string
4438
{
4539
return __('validate.credit-card');
4640
}

src/Rules/ValidDiscordUsername.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,16 @@ class ValidDiscordUsername implements Rule
88
{
99
/**
1010
* Check discord username is valid.
11-
*
12-
* @param string $attribute
13-
* @param mixed $value
14-
* @return bool
1511
*/
16-
public function passes($attribute, $value)
12+
public function passes($attribute, $value): bool
1713
{
1814
return preg_match('/^.{3,32}#[0-9]{4}$/', $value);
1915
}
2016

2117
/**
2218
* Get the validation error message.
23-
*
24-
* @return string
2519
*/
26-
public function message()
20+
public function message(): string
2721
{
2822
return __('validate.discord-username');
2923
}

src/Rules/ValidDomain.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,16 @@ class ValidDomain implements Rule
88
{
99
/**
1010
* Check domain name is valid.
11-
*
12-
* @param string $attribute
13-
* @param mixed $value
14-
* @return bool
1511
*/
16-
public function passes($attribute, $value)
12+
public function passes($attribute, $value): bool
1713
{
1814
return preg_match('/^(?:[-A-Za-z0-9]+\.)+[A-Za-z]{2,6}$/', $value);
1915
}
2016

2117
/**
2218
* Get the validation error message.
23-
*
24-
* @return string
2519
*/
26-
public function message()
20+
public function message(): string
2721
{
2822
return __('validate.domain');
2923
}

src/Rules/ValidDuplicate.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,8 @@ class ValidDuplicate implements Rule
88
{
99
/**
1010
* Check duplicate value.
11-
*
12-
* @param string $attribute
13-
* @param mixed $value
14-
* @return bool
1511
*/
16-
public function passes($attribute, $value)
12+
public function passes($attribute, $value): bool
1713
{
1814
$value = str_split($value);
1915

@@ -22,10 +18,8 @@ public function passes($attribute, $value)
2218

2319
/**
2420
* Get the validation error message.
25-
*
26-
* @return string
2721
*/
28-
public function message()
22+
public function message(): string
2923
{
3024
return __('validate.duplicate');
3125
}

0 commit comments

Comments
 (0)