Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Step 0 #35

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a:6:{s:9:"classesIn";a:1:{s:58:"Danielebarbaro\LaravelVatEuValidator\Rules\VatNumberFormat";a:6:{s:4:"name";s:15:"VatNumberFormat";s:14:"namespacedName";s:58:"Danielebarbaro\LaravelVatEuValidator\Rules\VatNumberFormat";s:9:"namespace";s:42:"Danielebarbaro\LaravelVatEuValidator\Rules";s:9:"startLine";i:8;s:7:"endLine";i:16;s:7:"methods";a:1:{s:8:"validate";a:6:{s:10:"methodName";s:8:"validate";s:9:"signature";s:62:"validate(string $attribute, mixed $value, Closure $fail): void";s:10:"visibility";s:6:"public";s:9:"startLine";i:10;s:7:"endLine";i:15;s:3:"ccn";i:2;}}}}s:8:"traitsIn";a:0:{}s:11:"functionsIn";a:0:{}s:14:"linesOfCodeFor";a:3:{s:11:"linesOfCode";i:17;s:18:"commentLinesOfCode";i:0;s:21:"nonCommentLinesOfCode";i:17;}s:15:"ignoredLinesFor";a:1:{i:0;i:8;}s:17:"executableLinesIn";a:2:{i:12;i:1;i:13;i:2;}}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a:6:{s:9:"classesIn";a:1:{s:57:"Danielebarbaro\LaravelVatEuValidator\Rules\VatNumberExist";a:6:{s:4:"name";s:14:"VatNumberExist";s:14:"namespacedName";s:57:"Danielebarbaro\LaravelVatEuValidator\Rules\VatNumberExist";s:9:"namespace";s:42:"Danielebarbaro\LaravelVatEuValidator\Rules";s:9:"startLine";i:9;s:7:"endLine";i:17;s:7:"methods";a:1:{s:8:"validate";a:6:{s:10:"methodName";s:8:"validate";s:9:"signature";s:62:"validate(string $attribute, mixed $value, Closure $fail): void";s:10:"visibility";s:6:"public";s:9:"startLine";i:11;s:7:"endLine";i:16;s:3:"ccn";i:2;}}}}s:8:"traitsIn";a:0:{}s:11:"functionsIn";a:0:{}s:14:"linesOfCodeFor";a:3:{s:11:"linesOfCode";i:18;s:18:"commentLinesOfCode";i:0;s:21:"nonCommentLinesOfCode";i:18;}s:15:"ignoredLinesFor";a:1:{i:0;i:9;}s:17:"executableLinesIn";a:2:{i:13;i:1;i:14;i:2;}}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a:6:{s:9:"classesIn";a:1:{s:52:"Danielebarbaro\LaravelVatEuValidator\Rules\VatNumber";a:6:{s:4:"name";s:9:"VatNumber";s:14:"namespacedName";s:52:"Danielebarbaro\LaravelVatEuValidator\Rules\VatNumber";s:9:"namespace";s:42:"Danielebarbaro\LaravelVatEuValidator\Rules";s:9:"startLine";i:8;s:7:"endLine";i:16;s:7:"methods";a:1:{s:8:"validate";a:6:{s:10:"methodName";s:8:"validate";s:9:"signature";s:62:"validate(string $attribute, mixed $value, Closure $fail): void";s:10:"visibility";s:6:"public";s:9:"startLine";i:10;s:7:"endLine";i:15;s:3:"ccn";i:2;}}}}s:8:"traitsIn";a:0:{}s:11:"functionsIn";a:0:{}s:14:"linesOfCodeFor";a:3:{s:11:"linesOfCode";i:17;s:18:"commentLinesOfCode";i:0;s:21:"nonCommentLinesOfCode";i:17;}s:15:"ignoredLinesFor";a:1:{i:0;i:8;}s:17:"executableLinesIn";a:2:{i:12;i:1;i:13;i:2;}}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a:6:{s:9:"classesIn";a:1:{s:63:"Danielebarbaro\LaravelVatEuValidator\Facades\VatValidatorFacade";a:6:{s:4:"name";s:18:"VatValidatorFacade";s:14:"namespacedName";s:63:"Danielebarbaro\LaravelVatEuValidator\Facades\VatValidatorFacade";s:9:"namespace";s:44:"Danielebarbaro\LaravelVatEuValidator\Facades";s:9:"startLine";i:15;s:7:"endLine";i:26;s:7:"methods";a:1:{s:17:"getFacadeAccessor";a:6:{s:10:"methodName";s:17:"getFacadeAccessor";s:9:"signature";s:27:"getFacadeAccessor(): string";s:10:"visibility";s:9:"protected";s:9:"startLine";i:22;s:7:"endLine";i:25;s:3:"ccn";i:1;}}}}s:8:"traitsIn";a:0:{}s:11:"functionsIn";a:0:{}s:14:"linesOfCodeFor";a:3:{s:11:"linesOfCode";i:27;s:18:"commentLinesOfCode";i:12;s:21:"nonCommentLinesOfCode";i:15;}s:15:"ignoredLinesFor";a:1:{i:0;i:15;}s:17:"executableLinesIn";a:1:{i:24;i:1;}}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a:6:{s:9:"classesIn";a:1:{s:64:"Danielebarbaro\LaravelVatEuValidator\VatValidatorServiceProvider";a:6:{s:4:"name";s:27:"VatValidatorServiceProvider";s:14:"namespacedName";s:64:"Danielebarbaro\LaravelVatEuValidator\VatValidatorServiceProvider";s:9:"namespace";s:36:"Danielebarbaro\LaravelVatEuValidator";s:9:"startLine";i:12;s:7:"endLine";i:51;s:7:"methods";a:2:{s:4:"boot";a:6:{s:10:"methodName";s:4:"boot";s:9:"signature";s:12:"boot(): void";s:10:"visibility";s:6:"public";s:9:"startLine";i:17;s:7:"endLine";i:42;s:3:"ccn";i:1;}s:8:"register";a:6:{s:10:"methodName";s:8:"register";s:9:"signature";s:16:"register(): void";s:10:"visibility";s:6:"public";s:9:"startLine";i:47;s:7:"endLine";i:50;s:3:"ccn";i:1;}}}}s:8:"traitsIn";a:0:{}s:11:"functionsIn";a:0:{}s:14:"linesOfCodeFor";a:3:{s:11:"linesOfCode";i:52;s:18:"commentLinesOfCode";i:15;s:21:"nonCommentLinesOfCode";i:37;}s:15:"ignoredLinesFor";a:1:{i:0;i:12;}s:17:"executableLinesIn";a:13:{i:22;i:1;i:25;i:1;i:23;i:2;i:24;i:3;i:30;i:4;i:33;i:4;i:31;i:5;i:32;i:6;i:38;i:7;i:41;i:7;i:39;i:8;i:40;i:9;i:49;i:10;}}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a:6:{s:9:"classesIn";a:1:{s:55:"Danielebarbaro\LaravelVatEuValidator\Vies\ViesException";a:6:{s:4:"name";s:13:"ViesException";s:14:"namespacedName";s:55:"Danielebarbaro\LaravelVatEuValidator\Vies\ViesException";s:9:"namespace";s:41:"Danielebarbaro\LaravelVatEuValidator\Vies";s:9:"startLine";i:7;s:7:"endLine";i:10;s:7:"methods";a:0:{}}}s:8:"traitsIn";a:0:{}s:11:"functionsIn";a:0:{}s:14:"linesOfCodeFor";a:3:{s:11:"linesOfCode";i:11;s:18:"commentLinesOfCode";i:1;s:21:"nonCommentLinesOfCode";i:10;}s:15:"ignoredLinesFor";a:1:{i:0;i:7;}s:17:"executableLinesIn";a:0:{}}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a:6:{s:9:"classesIn";a:1:{s:49:"Danielebarbaro\LaravelVatEuValidator\VatValidator";a:6:{s:4:"name";s:12:"VatValidator";s:14:"namespacedName";s:49:"Danielebarbaro\LaravelVatEuValidator\VatValidator";s:9:"namespace";s:36:"Danielebarbaro\LaravelVatEuValidator";s:9:"startLine";i:7;s:7:"endLine";i:173;s:7:"methods";a:8:{s:11:"__construct";a:6:{s:10:"methodName";s:11:"__construct";s:9:"signature";s:70:"__construct(?Danielebarbaro\LaravelVatEuValidator\Vies\Client $client)";s:10:"visibility";s:6:"public";s:9:"startLine";i:50;s:7:"endLine";i:55;s:3:"ccn";i:2;}s:18:"countryIsSupported";a:6:{s:10:"methodName";s:18:"countryIsSupported";s:9:"signature";s:41:"countryIsSupported(string $country): bool";s:10:"visibility";s:6:"public";s:9:"startLine";i:62;s:7:"endLine";i:65;s:3:"ccn";i:1;}s:14:"validateFormat";a:6:{s:10:"methodName";s:14:"validateFormat";s:9:"signature";s:39:"validateFormat(string $vatNumber): bool";s:10:"visibility";s:6:"public";s:9:"startLine";i:72;s:7:"endLine";i:91;s:3:"ccn";i:4;}s:17:"validateExistence";a:6:{s:10:"methodName";s:17:"validateExistence";s:9:"signature";s:42:"validateExistence(string $vatNumber): bool";s:10:"visibility";s:6:"public";s:9:"startLine";i:99;s:7:"endLine";i:110;s:3:"ccn";i:2;}s:9:"luhnCheck";a:6:{s:10:"methodName";s:9:"luhnCheck";s:9:"signature";s:27:"luhnCheck(string $vat): int";s:10:"visibility";s:6:"public";s:9:"startLine";i:119;s:7:"endLine";i:137;s:3:"ccn";i:4;}s:8:"validate";a:6:{s:10:"methodName";s:8:"validate";s:9:"signature";s:33:"validate(string $vatNumber): bool";s:10:"visibility";s:6:"public";s:9:"startLine";i:146;s:7:"endLine";i:149;s:3:"ccn";i:2;}s:10:"vatCleaner";a:6:{s:10:"methodName";s:10:"vatCleaner";s:9:"signature";s:37:"vatCleaner(string $vatNumber): string";s:10:"visibility";s:7:"private";s:9:"startLine";i:155;s:7:"endLine";i:160;s:3:"ccn";i:1;}s:8:"splitVat";a:6:{s:10:"methodName";s:8:"splitVat";s:9:"signature";s:34:"splitVat(string $vatNumber): array";s:10:"visibility";s:7:"private";s:9:"startLine";i:166;s:7:"endLine";i:172;s:3:"ccn";i:1;}}}}s:8:"traitsIn";a:0:{}s:11:"functionsIn";a:0:{}s:14:"linesOfCodeFor";a:3:{s:11:"linesOfCode";i:174;s:18:"commentLinesOfCode";i:48;s:21:"nonCommentLinesOfCode";i:126;}s:15:"ignoredLinesFor";a:1:{i:0;i:7;}s:17:"executableLinesIn";a:36:{i:52;i:2;i:53;i:3;i:64;i:4;i:74;i:5;i:75;i:6;i:78;i:7;i:79;i:8;i:82;i:9;i:84;i:10;i:85;i:11;i:87;i:12;i:90;i:13;i:101;i:14;i:102;i:15;i:104;i:16;i:105;i:17;i:106;i:18;i:109;i:19;i:121;i:20;i:122;i:21;i:123;i:22;i:124;i:23;i:125;i:24;i:126;i:25;i:127;i:26;i:128;i:27;i:129;i:28;i:133;i:29;i:136;i:30;i:148;i:31;i:157;i:32;i:159;i:33;i:168;i:34;i:169;i:34;i:170;i:34;i:171;i:34;}}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a:6:{s:9:"classesIn";a:1:{s:48:"Danielebarbaro\LaravelVatEuValidator\Vies\Client";a:6:{s:4:"name";s:6:"Client";s:14:"namespacedName";s:48:"Danielebarbaro\LaravelVatEuValidator\Vies\Client";s:9:"namespace";s:41:"Danielebarbaro\LaravelVatEuValidator\Vies";s:9:"startLine";i:8;s:7:"endLine";i:63;s:7:"methods";a:3:{s:11:"__construct";a:6:{s:10:"methodName";s:11:"__construct";s:9:"signature";s:25:"__construct(int $timeout)";s:10:"visibility";s:6:"public";s:9:"startLine";i:22;s:7:"endLine";i:24;s:3:"ccn";i:1;}s:5:"check";a:6:{s:10:"methodName";s:5:"check";s:9:"signature";s:51:"check(string $countryCode, string $vatNumber): bool";s:10:"visibility";s:6:"public";s:9:"startLine";i:35;s:7:"endLine";i:49;s:3:"ccn";i:2;}s:9:"getClient";a:6:{s:10:"methodName";s:9:"getClient";s:9:"signature";s:23:"getClient(): SoapClient";s:10:"visibility";s:9:"protected";s:9:"startLine";i:55;s:7:"endLine";i:62;s:3:"ccn";i:2;}}}}s:8:"traitsIn";a:0:{}s:11:"functionsIn";a:0:{}s:14:"linesOfCodeFor";a:3:{s:11:"linesOfCode";i:64;s:18:"commentLinesOfCode";i:21;s:21:"nonCommentLinesOfCode";i:43;}s:15:"ignoredLinesFor";a:1:{i:0;i:8;}s:17:"executableLinesIn";a:13:{i:24;i:3;i:38;i:4;i:39;i:4;i:40;i:4;i:41;i:4;i:42;i:4;i:43;i:4;i:44;i:5;i:45;i:6;i:48;i:7;i:57;i:8;i:58;i:9;i:61;i:10;}}
1 change: 1 addition & 0 deletions .phpunit.cache/test-results
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"version":1,"defects":[],"times":{"Danielebarbaro\\LaravelVatEuValidator\\Tests\\Rules\\CountryIsSupportedTest::testCountryIsSupported":0.027,"Danielebarbaro\\LaravelVatEuValidator\\Tests\\Rules\\CountryIsSupportedTest::testCountryIsNotSupported":0.001,"Danielebarbaro\\LaravelVatEuValidator\\Tests\\Rules\\VatNumberExistTest::testVatNumberExist":0.008,"Danielebarbaro\\LaravelVatEuValidator\\Tests\\Rules\\VatNumberExistTest::testVatNumberDoesNotExist":0.003,"Danielebarbaro\\LaravelVatEuValidator\\Tests\\Rules\\VatNumberFormatTest::testVatNumberFormat":0.002,"Danielebarbaro\\LaravelVatEuValidator\\Tests\\Rules\\VatNumberFormatTest::testVatNumberFormatNotExist":0.001,"Danielebarbaro\\LaravelVatEuValidator\\Tests\\Rules\\VatNumberTest::testVatNumber":0.002,"Danielebarbaro\\LaravelVatEuValidator\\Tests\\Rules\\VatNumberTest::testVatNumberNotExist":0.001,"Danielebarbaro\\LaravelVatEuValidator\\Tests\\VatValidatorFacadeTest::testVatValidatorFacade":0.001,"Danielebarbaro\\LaravelVatEuValidator\\Tests\\VatValidatorTest::testVatValidFormatFail":0,"Danielebarbaro\\LaravelVatEuValidator\\Tests\\VatValidatorTest::testVatValidFormat":0,"Danielebarbaro\\LaravelVatEuValidator\\Tests\\VatValidatorTest::testVatWrongFormat":0,"Danielebarbaro\\LaravelVatEuValidator\\Tests\\VatValidatorTest::testVatExist":0,"Danielebarbaro\\LaravelVatEuValidator\\Tests\\VatValidatorTest::testVatValid":0,"Danielebarbaro\\LaravelVatEuValidator\\Tests\\VatValidatorTest::testLuhnCheck":0.001,"Danielebarbaro\\LaravelVatEuValidator\\Tests\\Vies\\ViesTest::testClientEmptyDataException":8.779,"Danielebarbaro\\LaravelVatEuValidator\\Tests\\Vies\\ViesTest::testClientEmptyVatNumberException":0.425,"Danielebarbaro\\LaravelVatEuValidator\\Tests\\Vies\\ViesTest::testClientEmptyCountryException":0.378,"Danielebarbaro\\LaravelVatEuValidator\\Tests\\Vies\\ViesTest::testFailExistResponse":2.054}}
26 changes: 15 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,22 @@
}
],
"require": {
"php": "^8.0|^8.1|^8.2",
"php": "^8.2",
"ext-soap": "*",
"illuminate/contracts": "^8.73|^9.2|^10.0|^11.0",
"illuminate/support": "^v8.83.2|^9.2|^10.0|^11.0"
"ext-openssl": "*",
"illuminate/contracts": "^10.0|^11.0",
"illuminate/support": "^10.0|^11.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.3",
"nunomaduro/collision": "^5.10|^6.0|^8.0",
"nunomaduro/larastan": "^1.0|^2.0.1",
"orchestra/testbench": "^6.22|^7.0|^8.0|^9.0",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan-deprecation-rules": "^1.0",
"phpstan/phpstan-phpunit": "^1.0",
"phpunit/phpunit": "^9.5|^10.5"
"driftingly/rector-laravel": "^1.2",
"friendsofphp/php-cs-fixer": "^3.59",
"orchestra/testbench": "^8.1|^9.1",
"phpstan/extension-installer": "^1.4",
"phpstan/phpstan": "^1.4.7",
"phpstan/phpstan-deprecation-rules": "^1.2",
"phpstan/phpstan-phpunit": "^1.4",
"phpunit/phpunit": "^10.5|^11.0",
"rector/rector": "^1.1"
},
"autoload": {
"psr-4": {
Expand All @@ -48,6 +50,8 @@
}
},
"scripts": {
"rector": "vendor/bin/rector process",
"rector-dry": "vendor/bin/rector process --dry-run",
"test": "vendor/bin/phpunit",
"test-coverage": "vendor/bin/phpunit --coverage-html coverage",
"cs-check": "vendor/bin/phpcs",
Expand Down
3 changes: 0 additions & 3 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,4 @@ parameters:
paths:
- src
tmpDir: build/phpstan
checkOctaneCompatibility: true
checkModelProperties: true
checkMissingIterableValueType: false

34 changes: 34 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

use Rector\CodingStyle\Rector\ArrowFunction\StaticArrowFunctionRector;
use Rector\Config\RectorConfig;
use Rector\Set\ValueObject\SetList;
use Rector\TypeDeclaration\Rector\ClassMethod\AddVoidReturnTypeWhereNoReturnRector;
use RectorLaravel\Set\LaravelSetList;

return RectorConfig::configure()
->withPaths([
__DIR__.'/src',
__DIR__.'/tests',
])
->withPhpSets()
->withSets([
LaravelSetList::LARAVEL_100,
LaravelSetList::LARAVEL_110,

SetList::PHP_83,
SetList::PHP_82,
SetList::CODING_STYLE,
SetList::CODE_QUALITY,
SetList::TYPE_DECLARATION,

\Rector\Set\ValueObject\LevelSetList::UP_TO_PHP_82,
])
->withSkip([
StaticArrowFunctionRector::class,
])
->withRules([
AddVoidReturnTypeWhereNoReturnRector::class,
]);
27 changes: 11 additions & 16 deletions src/VatValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,13 @@ class VatValidator
'SK' => '\d{10}',
];

/**
* Vies Client.
*/
private ?Client $client;

/**
* VatValidator constructor.
* @param Client|null $client
*/
public function __construct(Client $client = null)
public function __construct(private ?Client $client = null)
{
$this->client = $client;

if (! $this->client) {
if (! $this->client instanceof \Danielebarbaro\LaravelVatEuValidator\Vies\Client) {
$this->client = new Client();
}
}
Expand All @@ -79,15 +72,15 @@ public static function countryIsSupported(string $country): bool
public function validateFormat(string $vatNumber): bool
{
$vatNumber = $this->vatCleaner($vatNumber);
list($country, $number) = $this->splitVat($vatNumber);
[$country, $number] = $this->splitVat($vatNumber);

if (! isset(self::$pattern_expression[$country])) {
return false;
}

$validate_rule = preg_match('/^' . self::$pattern_expression[$country] . '$/', $number) > 0;
$validate_rule = preg_match('/^' . self::$pattern_expression[$country] . '$/', (string) $number) > 0;

if ($validate_rule === true && $country === 'IT') {
if ($validate_rule && $country === 'IT') {
$result = self::luhnCheck($number);

return $result % 10 == 0;
Expand All @@ -107,7 +100,7 @@ public function validateExistence(string $vatNumber): bool
$vatNumber = $this->vatCleaner($vatNumber);
$result = $this->validateFormat($vatNumber);
if ($result) {
list($country, $number) = $this->splitVat($vatNumber);
[$country, $number] = $this->splitVat($vatNumber);
$result = $this->client->check($country, $number);
}

Expand All @@ -125,14 +118,16 @@ public static function luhnCheck(string $vat): int
{
$sum = 0;
$vat_array = str_split($vat);
for ($index = 0; $index < count($vat_array); $index++) {
$counter = count($vat_array);
for ($index = 0; $index < $counter; ++$index) {
$value = intval($vat_array[$index]);
if ($index % 2) {
$value = $value * 2;
if ($index % 2 !== 0) {
$value *= 2;
if ($value > 9) {
$value = 1 + ($value % 10);
}
}

$sum += $value;
}

Expand Down
14 changes: 6 additions & 8 deletions src/VatValidatorServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ class VatValidatorServiceProvider extends ServiceProvider
/**
* Bootstrap the application services.
*/
public function boot()
public function boot(): void
{
/**
* Register the "vat_number" validation rule.
*/
Validator::extend('vat_number', function ($attribute, $value, $parameters, $validator) {
Validator::extend('vat_number', static function ($attribute, $value, $parameters, $validator): bool {
$rule = new VatNumber();

return $rule->passes($attribute, $value);
Expand All @@ -28,7 +28,7 @@ public function boot()
/**
* Register the "vat_number_exist" validation rule.
*/
Validator::extend('vat_number_exist', function ($attribute, $value, $parameters, $validator) {
Validator::extend('vat_number_exist', static function ($attribute, $value, $parameters, $validator): bool {
$rule = new VatNumberExist();

return $rule->passes($attribute, $value);
Expand All @@ -37,7 +37,7 @@ public function boot()
/**
* Register the "vat_number_format" validation rule.
*/
Validator::extend('vat_number_format', function ($attribute, $value, $parameters, $validator) {
Validator::extend('vat_number_format', static function ($attribute, $value, $parameters, $validator): bool {
$rule = new VatNumberFormat();

return $rule->passes($attribute, $value);
Expand All @@ -47,10 +47,8 @@ public function boot()
/**
* Register the application services.
*/
public function register()
public function register(): void
{
$this->app->singleton(VatValidator::class, function (Container $app) {
return new VatValidator();
});
$this->app->singleton(VatValidator::class, fn (Container $app): \Danielebarbaro\LaravelVatEuValidator\VatValidator => new VatValidator());
}
}
17 changes: 4 additions & 13 deletions src/Vies/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,15 @@ class Client
*/
public const URL = 'https://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl';

/**
* @var int
*/
protected $timeout;

/**
* @var SoapClient
*/
private $client;
private ?\SoapClient $client = null;

/**
* Client constructor.
*
* @param int $timeout
*/
public function __construct(int $timeout = 10)
public function __construct(protected int $timeout = 10)
{
$this->timeout = $timeout;
}

/**
Expand All @@ -50,8 +41,8 @@ public function check(string $countryCode, string $vatNumber): bool
'vatNumber' => $vatNumber,
]
);
} catch (SoapFault $e) {
throw new ViesException($e->getMessage(), $e->getCode());
} catch (SoapFault $soapFault) {
throw new ViesException($soapFault->getMessage(), $soapFault->getCode());
}

return $response->valid;
Expand Down
4 changes: 2 additions & 2 deletions tests/Rules/CountryIsSupportedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

class CountryIsSupportedTest extends TestCase
{
public function testCountryIsSupported()
public function testCountryIsSupported(): void
{
self::assertTrue(VatValidator::countryIsSupported('AT'));
}

public function testCountryIsNotSupported()
public function testCountryIsNotSupported(): void
{
self::assertFalse(VatValidator::countryIsSupported('US'));
}
Expand Down
6 changes: 3 additions & 3 deletions tests/Rules/VatNumberExistTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ class VatNumberExistTest extends TestCase

protected string $fake_vat;

public function setUp(): void
protected function setUp(): void
{
parent::setUp();

$this->rule = new VatNumberExist();
$this->fake_vat = 'IT12345678901';
}

public function testSuccessVatNumberFormatExist()
public function testSuccessVatNumberFormatExist(): void
{
self::assertFalse($this->rule->passes('vat_number_exist', $this->fake_vat));
}

public function testSuccessVatNumberFormatExistMessage()
public function testSuccessVatNumberFormatExistMessage(): void
{
self::assertStringContainsString(
'The :attribute must be write in a valid number format {country_name}{vat_number}.',
Expand Down
Loading