Skip to content

Commit

Permalink
Merge pull request #90 from milwad-dev/refactor
Browse files Browse the repository at this point in the history
[1.x] Refactor
  • Loading branch information
milwad-dev authored Jun 8, 2024
2 parents 8eb0af8 + 7f5c2b6 commit d5ba2b9
Show file tree
Hide file tree
Showing 44 changed files with 161 additions and 438 deletions.
41 changes: 14 additions & 27 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,29 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
backupGlobals="false"
backupStaticAttributes="false"
beStrictAboutTestsThatDoNotTestAnything="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
verbose="true"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">

<testsuites>
<testsuite name="Tests">
<directory suffix="Test.php">./tests/</directory>
</testsuite>
</testsuites>
<coverage includeUncoveredFiles="false">
<include>
<directory suffix=".php">src/</directory>
</include>
</coverage>
<php>
<env name="APP_ENV" value="testing" />
</php>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" beStrictAboutTestsThatDoNotTestAnything="false" bootstrap="vendor/autoload.php" colors="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<testsuites>
<testsuite name="Tests">
<directory suffix="Test.php">./tests/</directory>
</testsuite>
</testsuites>
<php>
<env name="APP_ENV" value="testing"/>
</php>
<source>
<include>
<directory suffix=".php">src/</directory>
</include>
</source>
</phpunit>
29 changes: 29 additions & 0 deletions phpunit.xml.dist.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
backupGlobals="false"
backupStaticAttributes="false"
beStrictAboutTestsThatDoNotTestAnything="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
verbose="true"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">

<testsuites>
<testsuite name="Tests">
<directory suffix="Test.php">./tests/</directory>
</testsuite>
</testsuites>
<coverage includeUncoveredFiles="false">
<include>
<directory suffix=".php">src/</directory>
</include>
</coverage>
<php>
<env name="APP_ENV" value="testing" />
</php>
</phpunit>
8 changes: 2 additions & 6 deletions src/LaravelValidateServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,8 @@ class LaravelValidateServiceProvider extends ServiceProvider

/**
* Register files.
*
* @return void
*/
public function register()
public function register(): void
{
if ($this->app->runningInConsole()) {
$this->publishLangFiles();
Expand All @@ -68,10 +66,8 @@ private function publishLangFiles(): void

/**
* Publish config file.
*
* @return void
*/
private function publishConfigFile()
private function publishConfigFile(): void
{
$this->publishes([
__DIR__.'/../config/laravel-validate.php' => config_path('laravel-validate.php'),
Expand Down
10 changes: 2 additions & 8 deletions src/Rules/ValidBase64.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,16 @@ class ValidBase64 implements Rule
{
/**
* Check base64.
*
* @param string $attribute
* @param mixed $value
* @return bool
*/
public function passes($attribute, $value)
public function passes($attribute, $value): bool
{
return base64_encode(base64_decode($value, true)) === $value;
}

/**
* Get the validation error message.
*
* @return string
*/
public function message()
public function message(): string
{
return __('validate.base64');
}
Expand Down
12 changes: 3 additions & 9 deletions src/Rules/ValidBitcoinAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,17 @@
class ValidBitcoinAddress implements Rule
{
/**
* Check bitcoin address.
*
* @param string $attribute
* @param mixed $value
* @return bool
* Check bitcoin address is valid.
*/
public function passes($attribute, $value)
public function passes($attribute, $value): bool
{
return preg_match('/^(?:bc1|[13])[a-zA-HJ-NP-Z0-9]{25,39}$/', $value);
}

/**
* Get the validation error message.
*
* @return string
*/
public function message()
public function message(): string
{
return __('validate.bitcoin-address');
}
Expand Down
10 changes: 2 additions & 8 deletions src/Rules/ValidCamelCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,16 @@ class ValidCamelCase implements Rule
{
/**
* Check value is camel case.
*
* @param string $attribute
* @param mixed $value
* @return bool
*/
public function passes($attribute, $value)
public function passes($attribute, $value): bool
{
return preg_match('/^(?:\p{Lu}?\p{Ll}+)(?:\p{Lu}\p{Ll}+)*$/u', $value);
}

/**
* Get the validation error message.
*
* @return string
*/
public function message()
public function message(): string
{
return __('validate.camel-case');
}
Expand Down
10 changes: 2 additions & 8 deletions src/Rules/ValidCapitalCharWithNumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,16 @@ class ValidCapitalCharWithNumber implements Rule
{
/**
* Check all words are capital & with hyphen & number.
*
* @param string $attribute
* @param mixed $value
* @return bool
*/
public function passes($attribute, $value)
public function passes($attribute, $value): bool
{
return preg_match('/[A-Z]{2,}-\d+/', $value);
}

/**
* Get the validation error message.
*
* @return string
*/
public function message()
public function message(): string
{
return __('validate.capital-char-with-number');
}
Expand Down
10 changes: 2 additions & 8 deletions src/Rules/ValidCarNumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,16 @@ class ValidCarNumber implements Rule
{
/**
* Check car number is valid.
*
* @param string $attribute
* @param mixed $value
* @return bool
*/
public function passes($attribute, $value)
public function passes($attribute, $value): bool
{
return preg_match('/^[A-Z]{2}[0-9]{2}[A-Z]{2}[0-9]{4}$/', $value);
}

/**
* Get the validation error message.
*
* @return string
*/
public function message()
public function message(): string
{
return __('validate.car-number');
}
Expand Down
10 changes: 2 additions & 8 deletions src/Rules/ValidCartNumberIran.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,8 @@ class ValidCartNumberIran implements Rule
{
/**
* Check cart number is valid.
*
* @param string $attribute
* @param mixed $value
* @return bool
*/
public function passes($attribute, $value)
public function passes($attribute, $value): bool
{
$cardToArr = str_split($value);
$cardTotal = 0;
Expand All @@ -31,10 +27,8 @@ public function passes($attribute, $value)

/**
* Get the validation error message.
*
* @return string
*/
public function message()
public function message(): string
{
return __('validate.cart-number-iran');
}
Expand Down
10 changes: 2 additions & 8 deletions src/Rules/ValidCreditCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,8 @@ class ValidCreditCard implements Rule
{
/**
* Check if the credit card number is valid using the Luhn algorithm.
*
* @param string $attribute
* @param mixed $value
* @return bool
*/
public function passes($attribute, $value)
public function passes($attribute, $value): bool
{
$value = preg_replace('/\D/', '', $value);

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

/**
* Get the validation error message.
*
* @return string
*/
public function message()
public function message(): string
{
return __('validate.credit-card');
}
Expand Down
10 changes: 2 additions & 8 deletions src/Rules/ValidDiscordUsername.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,16 @@ class ValidDiscordUsername implements Rule
{
/**
* Check discord username is valid.
*
* @param string $attribute
* @param mixed $value
* @return bool
*/
public function passes($attribute, $value)
public function passes($attribute, $value): bool
{
return preg_match('/^.{3,32}#[0-9]{4}$/', $value);
}

/**
* Get the validation error message.
*
* @return string
*/
public function message()
public function message(): string
{
return __('validate.discord-username');
}
Expand Down
10 changes: 2 additions & 8 deletions src/Rules/ValidDomain.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,16 @@ class ValidDomain implements Rule
{
/**
* Check domain name is valid.
*
* @param string $attribute
* @param mixed $value
* @return bool
*/
public function passes($attribute, $value)
public function passes($attribute, $value): bool
{
return preg_match('/^(?:[-A-Za-z0-9]+\.)+[A-Za-z]{2,6}$/', $value);
}

/**
* Get the validation error message.
*
* @return string
*/
public function message()
public function message(): string
{
return __('validate.domain');
}
Expand Down
10 changes: 2 additions & 8 deletions src/Rules/ValidDuplicate.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,8 @@ class ValidDuplicate implements Rule
{
/**
* Check duplicate value.
*
* @param string $attribute
* @param mixed $value
* @return bool
*/
public function passes($attribute, $value)
public function passes($attribute, $value): bool
{
$value = str_split($value);

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

/**
* Get the validation error message.
*
* @return string
*/
public function message()
public function message(): string
{
return __('validate.duplicate');
}
Expand Down
10 changes: 2 additions & 8 deletions src/Rules/ValidDuplicateCharacter.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,8 @@ class ValidDuplicateCharacter implements Rule
{
/**
* Check duplicate characters, splitted by comma.
*
* @param string $attribute
* @param mixed $value
* @return bool
*/
public function passes($attribute, $value)
public function passes($attribute, $value): bool
{
$value = explode(',', $value);

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

/**
* Get the validation error message.
*
* @return string
*/
public function message()
public function message(): string
{
return __('validate.duplicate_character');
}
Expand Down
Loading

0 comments on commit d5ba2b9

Please sign in to comment.