Skip to content

Commit

Permalink
Review rector config
Browse files Browse the repository at this point in the history
  • Loading branch information
danielebarbaro committed Jun 16, 2024
1 parent ac6314e commit 671e060
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 11 deletions.
8 changes: 7 additions & 1 deletion rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\Set\ValueObject\LevelSetList;
use Rector\Set\ValueObject\SetList;
use Rector\TypeDeclaration\Rector\ClassMethod\AddVoidReturnTypeWhereNoReturnRector;
use RectorLaravel\Set\LaravelSetList;
Expand All @@ -16,14 +17,19 @@
->withSets([
LaravelSetList::LARAVEL_100,
LaravelSetList::LARAVEL_110,
LaravelSetList::LARAVEL_CODE_QUALITY,
LaravelSetList::LARAVEL_FACADE_ALIASES_TO_FULL_NAMES,
LaravelSetList::LARAVEL_ARRAY_STR_FUNCTION_TO_STATIC_CALL,
LaravelSetList::LARAVEL_LEGACY_FACTORIES_TO_CLASSES,

SetList::PHP_83,
SetList::PHP_82,
LevelSetList::UP_TO_PHP_82,

SetList::CODING_STYLE,
SetList::CODE_QUALITY,
SetList::TYPE_DECLARATION,

\Rector\Set\ValueObject\LevelSetList::UP_TO_PHP_82,
])
->withRules([
AddVoidReturnTypeWhereNoReturnRector::class,
Expand Down
6 changes: 3 additions & 3 deletions src/VatValidatorServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,23 @@ public function boot(): void
*/
Validator::extend('vat_number', static function ($attribute, $value, $parameters, $validator): void {
$rule = new VatNumber();
$rule->validate($attribute, $value, fn (string $message = null) => null);
$rule->validate($attribute, $value, static fn (string $message = null): null => null);
});

/**
* Register the "vat_number_exist" validation rule.
*/
Validator::extend('vat_number_exist', static function ($attribute, $value, $parameters, $validator): void {
$rule = new VatNumberExist();
$rule->validate($attribute, $value, fn (string $message = null) => null);
$rule->validate($attribute, $value, static fn (string $message = null): null => null);
});

/**
* Register the "vat_number_format" validation rule.
*/
Validator::extend('vat_number_format', static function ($attribute, $value, $parameters, $validator): void {
$rule = new VatNumberFormat();
$rule->validate($attribute, $value, fn (string $message = null) => null);
$rule->validate($attribute, $value, static fn (string $message = null): null => null);
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/Vies/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function check(string $countryCode, string $vatNumber): bool
*/
protected function getClient(): SoapClient
{
if ($this->client === null) {
if (!$this->client instanceof \SoapClient) {
$this->client = new SoapClient(self::URL, ['connection_timeout' => $this->timeout]);
}

Expand Down
4 changes: 2 additions & 2 deletions tests/Rules/VatNumberExistTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function testVatNumberExist(): void
->with($fake_vat)
->andReturn(true);

$this->assertNull($rule->validate('vat_number_exist', $fake_vat, function () {
$this->assertNull($rule->validate('vat_number_exist', $fake_vat, function (): never {
$this->fail('Validation should not fail');
}));
}
Expand All @@ -36,7 +36,7 @@ public function testVatNumberDoesNotExist(): void
$this->expectException(\Exception::class);
$this->expectExceptionMessage('The :attribute must be write in a valid number format {country_name}{vat_number}.');

$rule->validate('vat_number_exist', $fake_vat, function ($message) {
$rule->validate('vat_number_exist', $fake_vat, static function ($message): never {
throw new \Exception($message);
});
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Rules/VatNumberFormatTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function testVatNumberFormat(): void
->with($fake_vat)
->andReturn(true);

$this->assertNull($rule->validate('vat_number_format', $fake_vat, function () {
$this->assertNull($rule->validate('vat_number_format', $fake_vat, function (): never {
$this->fail('Validation should not fail');
}));
}
Expand All @@ -36,7 +36,7 @@ public function testVatNumberFormatNotExist(): void
$this->expectException(\Exception::class);
$this->expectExceptionMessage('VAT number :attribute not exist.');

$rule->validate('vat_number_format', $fake_vat, function ($message) {
$rule->validate('vat_number_format', $fake_vat, static function ($message): never {
throw new \Exception($message);
});
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Rules/VatNumberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function testVatNumber(): void
->with($fake_vat)
->andReturn(true);

$this->assertNull($rule->validate('vat_number', $fake_vat, function () {
$this->assertNull($rule->validate('vat_number', $fake_vat, function (): never {
$this->fail('Validation should not fail');
}));
}
Expand All @@ -36,7 +36,7 @@ public function testVatNumberNotExist(): void
$this->expectException(\Exception::class);
$this->expectExceptionMessage('The :attribute must be a valid VAT number.');

$rule->validate('vat_number', $fake_vat, function ($message) {
$rule->validate('vat_number', $fake_vat, static function ($message): never {
throw new \Exception($message);
});
}
Expand Down

0 comments on commit 671e060

Please sign in to comment.