From 16e44300ff31693f93bfd045266fb56c7175d429 Mon Sep 17 00:00:00 2001 From: Mikus Rozenbergs Date: Tue, 13 Apr 2021 17:24:17 +0300 Subject: [PATCH 1/9] full response info --- src/Vies/Client.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Vies/Client.php b/src/Vies/Client.php index 38d9c0a..dae9c21 100644 --- a/src/Vies/Client.php +++ b/src/Vies/Client.php @@ -43,6 +43,19 @@ public function __construct(int $timeout = 10) * @throws ViesException */ public function checkVat(string $countryCode, string $vatNumber) : bool + { + return (bool)$this->getInfo($countryCode, $vatNumber)->valid; + } + + /** + * @param string $countryCode + * @param string $vatNumber + * + * @return object + * + * @throws ViesException + */ + public function getInfo(string $countryCode, string $vatNumber) : object { try { $response = $this->getClient()->checkVat( @@ -51,11 +64,12 @@ public function checkVat(string $countryCode, string $vatNumber) : bool 'vatNumber' => $vatNumber ) ); + } catch (SoapFault $e) { throw new ViesException($e->getMessage(), $e->getCode()); } - return (bool) $response->valid; + return $response; } /** From 389eeb7afc65c5bca37f2d77fc513699eb2edb67 Mon Sep 17 00:00:00 2001 From: Mikus Rozenbergs Date: Wed, 14 Apr 2021 09:38:42 +0300 Subject: [PATCH 2/9] disable "prefer-stable: true" --- composer.json | 1 - 1 file changed, 1 deletion(-) diff --git a/composer.json b/composer.json index 6d51481..4b5d5ac 100755 --- a/composer.json +++ b/composer.json @@ -31,7 +31,6 @@ "config": { "preferred-install": "dist" }, - "prefer-stable": true, "suggest": { "ibericode/vat-bundle": "Symfony bundle for integrating this package", "ext-soap": "Needed to support VIES VAT number validation" From 60245b40bcf0a2b85546184d61e4c7364ac93031 Mon Sep 17 00:00:00 2001 From: Mikus Rozenbergs Date: Wed, 14 Apr 2021 09:40:46 +0300 Subject: [PATCH 3/9] reverted: disable "prefer-stable: true" --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index 4b5d5ac..6d51481 100755 --- a/composer.json +++ b/composer.json @@ -31,6 +31,7 @@ "config": { "preferred-install": "dist" }, + "prefer-stable": true, "suggest": { "ibericode/vat-bundle": "Symfony bundle for integrating this package", "ext-soap": "Needed to support VIES VAT number validation" From b310273497f8929e454b9d493828d165b1e332e7 Mon Sep 17 00:00:00 2001 From: Mikus Rozenbergs Date: Thu, 18 Apr 2024 17:06:10 +0300 Subject: [PATCH 4/9] bump minimal PHP version add php-cs-fixer remove php_codesniffer upgrade phpUnit version --- .github/workflows/build.yml | 12 +++++----- .gitignore | 1 + .php-cs-fixer.dist.php | 12 ++++++++++ composer.json | 6 ++--- phpunit.xml.dist | 43 ++++++++++++----------------------- src/Rates.php | 3 +-- src/Vies/Client.php | 3 +-- tests/Clients/ClientsTest.php | 9 +++++--- tests/CountriesTest.php | 14 ++++++------ tests/GeolocatorTest.php | 7 +++--- tests/RatesTest.php | 2 +- tests/ValidatorTest.php | 35 ++++++++++++---------------- 12 files changed, 70 insertions(+), 77 deletions(-) create mode 100644 .php-cs-fixer.dist.php diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 57f081a..e0f5994 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,7 +1,8 @@ name: Build -on: [ push, pull_request ] - +on: + - pull_request + - push jobs: tests: runs-on: "ubuntu-latest" @@ -12,7 +13,7 @@ jobs: - "8.3" steps: - name: "Checkout" - uses: "actions/checkout@v2" + uses: "actions/checkout@v4" - name: "Install PHP" uses: "shivammathur/setup-php@v2" @@ -23,9 +24,8 @@ jobs: - name: "Install dependencies with Composer" uses: "ramsey/composer-install@v2" - - name: "Run phpcs" - if: ${{ matrix.php-version == '8.3' }} - run: "vendor/bin/phpcs -n -s --report=checkstyle | cs2pr" + - name: "Run PHP CS Fixer" + run: "./vendor/bin/php-cs-fixer fix --format checkstyle | cs2pr" - name: "Run PHPUnit" run: "vendor/bin/phpunit" diff --git a/.gitignore b/.gitignore index 8e26f45..ec2000c 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ vendor composer.lock .idea .phpunit.result.cache +.php-cs-fixer.cache diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php new file mode 100644 index 0000000..1a07c4d --- /dev/null +++ b/.php-cs-fixer.dist.php @@ -0,0 +1,12 @@ +in(['src', 'tests']) +; + +return (new PhpCsFixer\Config()) + ->setRules([ + '@PSR12' => true, + ]) + ->setFinder($finder) + ; diff --git a/composer.json b/composer.json index 213ac88..0fe3f11 100755 --- a/composer.json +++ b/composer.json @@ -10,13 +10,13 @@ } ], "require": { - "php": ">=8.1", + "php": ">=8.2", "ext-curl": "*", "ext-json": "*" }, "require-dev": { - "phpunit/phpunit": "^9.5", - "squizlabs/php_codesniffer": "^3.5" + "phpunit/phpunit": "^11.1", + "friendsofphp/php-cs-fixer": "^3.54" }, "autoload": { "psr-4": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 812ee72..fe907ce 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,31 +1,16 @@ - - - - ./tests - - - - - ./src - - - - - + + + + ./tests + + + + + + + + ./src + + diff --git a/src/Rates.php b/src/Rates.php index 533c7b2..4465a16 100644 --- a/src/Rates.php +++ b/src/Rates.php @@ -153,7 +153,6 @@ public function getRateForCountry(string $countryCode, string $level = self::RAT */ public function getRateForCountryOnDate(string $countryCode, \DateTimeInterface $datetime, string $level = self::RATE_STANDARD): float { - $activePeriod = $this->resolvePeriod($countryCode, $datetime); - return $activePeriod->getRate($level); + return $this->resolvePeriod($countryCode, $datetime)->getRate($level); } } diff --git a/src/Vies/Client.php b/src/Vies/Client.php index d815181..2b9ae44 100644 --- a/src/Vies/Client.php +++ b/src/Vies/Client.php @@ -55,7 +55,7 @@ public function checkVat(string $countryCode, string $vatNumber): bool * * @throws ViesException */ - public function getInfo(string $countryCode, string $vatNumber) : object + public function getInfo(string $countryCode, string $vatNumber): object { try { $response = $this->getClient()->checkVat( @@ -64,7 +64,6 @@ public function getInfo(string $countryCode, string $vatNumber) : object 'vatNumber' => $vatNumber ) ); - } catch (SoapFault $e) { throw new ViesException($e->getMessage(), $e->getCode()); } diff --git a/tests/Clients/ClientsTest.php b/tests/Clients/ClientsTest.php index e3d2055..0f87972 100644 --- a/tests/Clients/ClientsTest.php +++ b/tests/Clients/ClientsTest.php @@ -2,18 +2,21 @@ namespace Ibericode\Vat\Tests\Clients; +use Ibericode\Vat\Clients\ClientException; use Ibericode\Vat\Clients\IbericodeVatRatesClient; use Ibericode\Vat\Clients\Client; use Ibericode\Vat\Period; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; class ClientsTest extends TestCase { /** * @group remote-http - * @dataProvider clientProvider + * @throws ClientException */ - public function testClient(Client $client) + #[DataProvider('clientsProvider')] + public function testClient(Client $client): void { $data = $client->fetch(); $this->assertIsArray($data); @@ -22,7 +25,7 @@ public function testClient(Client $client) $this->assertInstanceOf(Period::class, $data['NL'][0]); } - public function clientProvider() + public static function clientsProvider(): \Generator { yield [new IbericodeVatRatesClient()]; } diff --git a/tests/CountriesTest.php b/tests/CountriesTest.php index 85381bc..d97d13e 100644 --- a/tests/CountriesTest.php +++ b/tests/CountriesTest.php @@ -9,14 +9,14 @@ class CountriesTest extends TestCase { - public function testIterator() + public function testIterator(): void { $countries = new Countries(); $this->assertCount(249, $countries); } - public function testArrayAccess() + public function testArrayAccess(): void { $countries = new Countries(); @@ -27,35 +27,35 @@ public function testArrayAccess() $countries['FOO']; } - public function testArrayAccessWithInvalidCountryCode() + public function testArrayAccessWithInvalidCountryCode(): void { $countries = new Countries(); $this->expectException(Exception::class); $countries['FOO']; } - public function testArrayAccessSetValue() + public function testArrayAccessSetValue(): void { $countries = new Countries(); $this->expectException(Exception::class); $countries['FOO'] = 'bar'; } - public function testArrayAccessUnsetValue() + public function testArrayAccessUnsetValue(): void { $countries = new Countries(); $this->expectException(Exception::class); unset($countries['FOO']); } - public function testHasCode() + public function testHasCode(): void { $countries = new Countries(); $this->assertFalse($countries->hasCountryCode('FOO')); $this->assertTrue($countries->hasCountryCode('NL')); } - public function testIsCodeInEU() + public function testIsCodeInEU(): void { $countries = new Countries(); $this->assertFalse($countries->isCountryCodeInEU('FOO')); diff --git a/tests/GeolocatorTest.php b/tests/GeolocatorTest.php index 9f2c2ba..137ffdc 100644 --- a/tests/GeolocatorTest.php +++ b/tests/GeolocatorTest.php @@ -3,22 +3,23 @@ namespace Ibericode\Vat\Tests; use Ibericode\Vat\Geolocator; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; class GeolocatorTest extends TestCase { /** - * @dataProvider provider * @group remote-http */ - public function testClient($service) + #[DataProvider('servicesProvider')] + public function testService($service): void { $geolocator = new Geolocator($service); $country = $geolocator->locateIpAddress('8.8.8.8'); $this->assertEquals('US', $country); } - public function provider() + public static function servicesProvider(): \Generator { yield ['ip2c.org']; } diff --git a/tests/RatesTest.php b/tests/RatesTest.php index 12e865b..0bb596f 100644 --- a/tests/RatesTest.php +++ b/tests/RatesTest.php @@ -19,7 +19,7 @@ protected function setUp(): void } } - private function getRatesClientMock() + private function getRatesClientMock(): \PHPUnit\Framework\MockObject\MockObject { $client = $this->getMockBuilder(IbericodeVatRatesClient::class) ->getMock(); diff --git a/tests/ValidatorTest.php b/tests/ValidatorTest.php index 847bc49..64d78f8 100644 --- a/tests/ValidatorTest.php +++ b/tests/ValidatorTest.php @@ -3,6 +3,7 @@ namespace Ibericode\Vat\Tests; use Ibericode\Vat\Validator; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; /** @@ -12,9 +13,9 @@ class ValidatorTest extends TestCase { /** - * @covers Validator::validateVatNumberFormat + * @coversXXX Validator::validateVatNumberFormat */ - public function testValidateVatNumberFormat() + public function testValidateVatNumberFormat(): void { $valid = [ 'ATU12345678', @@ -118,16 +119,14 @@ public function testValidateVatNumberFormat() } } - /** - * @dataProvider validIpAddresses - */ - public function testValidateIpAddressWithValid($value) + #[DataProvider('validIpAddresses')] + public function testValidateIpAddressWithValid($value): void { $validator = new Validator(); $this->assertTrue($validator->validateIpAddress($value)); } - public function validIpAddresses() + public static function validIpAddresses(): array { return [ ['8.8.8.8'], @@ -135,16 +134,14 @@ public function validIpAddresses() ]; } - /** - * @dataProvider invalidIpAddresses - */ - public function testValidateIpAddressWithInvalidValues($value) + #[DataProvider('invalidIpAddresses')] + public function testValidateIpAddressWithInvalidValues($value): void { $validator = new Validator(); $this->assertFalse($validator->validateIpAddress($value)); } - public function invalidIpAddresses() + public static function invalidIpAddresses(): array { return [ ['0.8.8.8.8'], @@ -153,18 +150,14 @@ public function invalidIpAddresses() ]; } - /** - * @dataProvider validCountryCodes - */ - public function testValidateCountryCodeWithValidValues($value) + #[DataProvider('validCountryCodes')] + public function testValidateCountryCodeWithValidValues($value): void { $validator = new Validator(); $this->assertTrue($validator->validateCountryCode($value)); } - /** - * @dataProvider invalidCountryCodes - */ + #[DataProvider('invalidCountryCodes')] public function testValidateCountryCodeWithInvalidValues($value) { $validator = new Validator(); @@ -172,7 +165,7 @@ public function testValidateCountryCodeWithInvalidValues($value) } - public function validCountryCodes() + public static function validCountryCodes(): array { return [ ['NL'], @@ -182,7 +175,7 @@ public function validCountryCodes() ]; } - public function invalidCountryCodes() + public static function invalidCountryCodes(): array { return [ ['FOO'], From de0df01cec77eb9fe27fa0c215f8bb9a4dfc4ff7 Mon Sep 17 00:00:00 2001 From: Mikus Rozenbergs Date: Thu, 22 Aug 2024 11:30:21 +0300 Subject: [PATCH 5/9] add php 8.1 workflow --- .github/workflows/build.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e0f5994..3034c8e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -9,6 +9,7 @@ jobs: strategy: matrix: php-version: + - "8.1" - "8.2" - "8.3" steps: From 9cc55875be39e9c3b489c04dcc5cbcfe7651848e Mon Sep 17 00:00:00 2001 From: Mikus Rozenbergs Date: Thu, 22 Aug 2024 11:31:36 +0300 Subject: [PATCH 6/9] revert php 8.1 workflow --- .github/workflows/build.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3034c8e..e0f5994 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -9,7 +9,6 @@ jobs: strategy: matrix: php-version: - - "8.1" - "8.2" - "8.3" steps: From 52ee9586368f75c9126ea62e9726ea5fd45860f4 Mon Sep 17 00:00:00 2001 From: Mikus Rozenbergs Date: Thu, 22 Aug 2024 11:43:50 +0300 Subject: [PATCH 7/9] bump ramsey/composer-install version --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e0f5994..3e0457d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -22,7 +22,7 @@ jobs: tools: "cs2pr" - name: "Install dependencies with Composer" - uses: "ramsey/composer-install@v2" + uses: "ramsey/composer-install@v3" - name: "Run PHP CS Fixer" run: "./vendor/bin/php-cs-fixer fix --format checkstyle | cs2pr" From 475a94ac126318409353436c532db7932f4c2b7d Mon Sep 17 00:00:00 2001 From: Mikus Rozenbergs Date: Thu, 22 Aug 2024 16:22:30 +0300 Subject: [PATCH 8/9] Fix unserialize() errors when running tests on PHP 8.3. https://php.watch/versions/8.3/unserialize-E-WARNING --- src/Rates.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Rates.php b/src/Rates.php index 4465a16..cd7ae67 100644 --- a/src/Rates.php +++ b/src/Rates.php @@ -71,7 +71,7 @@ private function loadFromFile(): void throw new Exception("Unserializable file content"); } - $data = unserialize($contents, [ + $data = @unserialize($contents, [ 'allowed_classes' => [ Period::class, DateTimeImmutable::class From 91c3b0cfe0e70523806de0f9d6d460292b51806f Mon Sep 17 00:00:00 2001 From: Mikus Rozenbergs Date: Thu, 22 Aug 2024 16:25:46 +0300 Subject: [PATCH 9/9] bump minimal PHP version --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0b5f745..7809716 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ This is a simple PHP library to help you deal with Europe's VAT rules. ## Installation -[PHP](https://php.net) version 8.1 or higher with the CURL and JSON extension is required. +[PHP](https://php.net) version 8.2 or higher with the CURL and JSON extension is required. For VAT number existence checking, the PHP SOAP extension is required as well.