Skip to content

Commit e370a94

Browse files
Merge pull request #68 from mixisLv/upgrade-to-php82
Add Client::getInfo method. Replace phpCodeSniffer with php-cs-fixer, PSR-12 adherance, bump minimal PHP version.
2 parents ac67615 + 91c3b0c commit e370a94

File tree

13 files changed

+86
-79
lines changed

13 files changed

+86
-79
lines changed

.github/workflows/build.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
name: Build
22

3-
on: [ push, pull_request ]
4-
3+
on:
4+
- pull_request
5+
- push
56
jobs:
67
tests:
78
runs-on: "ubuntu-latest"
@@ -12,7 +13,7 @@ jobs:
1213
- "8.3"
1314
steps:
1415
- name: "Checkout"
15-
uses: "actions/checkout@v2"
16+
uses: "actions/checkout@v4"
1617

1718
- name: "Install PHP"
1819
uses: "shivammathur/setup-php@v2"
@@ -21,11 +22,10 @@ jobs:
2122
tools: "cs2pr"
2223

2324
- name: "Install dependencies with Composer"
24-
uses: "ramsey/composer-install@v2"
25+
uses: "ramsey/composer-install@v3"
2526

26-
- name: "Run phpcs"
27-
if: ${{ matrix.php-version == '8.3' }}
28-
run: "vendor/bin/phpcs -n -s --report=checkstyle | cs2pr"
27+
- name: "Run PHP CS Fixer"
28+
run: "./vendor/bin/php-cs-fixer fix --format checkstyle | cs2pr"
2929

3030
- name: "Run PHPUnit"
3131
run: "vendor/bin/phpunit"

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ vendor
22
composer.lock
33
.idea
44
.phpunit.result.cache
5+
.php-cs-fixer.cache

.php-cs-fixer.dist.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
$finder = (new PhpCsFixer\Finder())
4+
->in(['src', 'tests'])
5+
;
6+
7+
return (new PhpCsFixer\Config())
8+
->setRules([
9+
'@PSR12' => true,
10+
])
11+
->setFinder($finder)
12+
;

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ This is a simple PHP library to help you deal with Europe's VAT rules.
1717

1818
## Installation
1919

20-
[PHP](https://php.net) version 8.1 or higher with the CURL and JSON extension is required.
20+
[PHP](https://php.net) version 8.2 or higher with the CURL and JSON extension is required.
2121

2222
For VAT number existence checking, the PHP SOAP extension is required as well.
2323

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
}
1111
],
1212
"require": {
13-
"php": ">=8.1",
13+
"php": ">=8.2",
1414
"ext-curl": "*",
1515
"ext-json": "*"
1616
},
1717
"require-dev": {
18-
"phpunit/phpunit": "^9.5",
19-
"squizlabs/php_codesniffer": "^3.5"
18+
"phpunit/phpunit": "^11.1",
19+
"friendsofphp/php-cs-fixer": "^3.54"
2020
},
2121
"autoload": {
2222
"psr-4": {

phpunit.xml.dist

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,16 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit backupGlobals="false"
3-
backupStaticAttributes="false"
4-
beStrictAboutTestsThatDoNotTestAnything="true"
5-
beStrictAboutOutputDuringTests="true"
6-
bootstrap="vendor/autoload.php"
7-
colors="true"
8-
convertErrorsToExceptions="false"
9-
convertNoticesToExceptions="false"
10-
convertWarningsToExceptions="false"
11-
failOnRisky="true"
12-
failOnWarning="true"
13-
processIsolation="false"
14-
stopOnError="false"
15-
stopOnFailure="false"
16-
verbose="true"
17-
>
18-
<testsuites>
19-
<testsuite name="VAT Test Suite">
20-
<directory suffix="Test.php">./tests</directory>
21-
</testsuite>
22-
</testsuites>
23-
<coverage processUncoveredFiles="true">
24-
<include>
25-
<directory suffix=".php">./src</directory>
26-
</include>
27-
</coverage>
28-
<php>
29-
<ini name="error_reporting" value="-1"/>
30-
</php>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" beStrictAboutTestsThatDoNotTestAnything="true" beStrictAboutOutputDuringTests="true" bootstrap="vendor/autoload.php" colors="true" failOnRisky="true" failOnWarning="true" processIsolation="false" stopOnError="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.1/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
3+
<testsuites>
4+
<testsuite name="VAT Test Suite">
5+
<directory suffix="Test.php">./tests</directory>
6+
</testsuite>
7+
</testsuites>
8+
<php>
9+
<ini name="error_reporting" value="-1"/>
10+
</php>
11+
<source>
12+
<include>
13+
<directory suffix=".php">./src</directory>
14+
</include>
15+
</source>
3116
</phpunit>

src/Rates.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ private function loadFromFile(): void
7171
throw new Exception("Unserializable file content");
7272
}
7373

74-
$data = unserialize($contents, [
74+
$data = @unserialize($contents, [
7575
'allowed_classes' => [
7676
Period::class,
7777
DateTimeImmutable::class
@@ -153,7 +153,6 @@ public function getRateForCountry(string $countryCode, string $level = self::RAT
153153
*/
154154
public function getRateForCountryOnDate(string $countryCode, \DateTimeInterface $datetime, string $level = self::RATE_STANDARD): float
155155
{
156-
$activePeriod = $this->resolvePeriod($countryCode, $datetime);
157-
return $activePeriod->getRate($level);
156+
return $this->resolvePeriod($countryCode, $datetime)->getRate($level);
158157
}
159158
}

src/Vies/Client.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,19 @@ public function __construct(int $timeout = 10)
4343
* @throws ViesException
4444
*/
4545
public function checkVat(string $countryCode, string $vatNumber): bool
46+
{
47+
return (bool)$this->getInfo($countryCode, $vatNumber)->valid;
48+
}
49+
50+
/**
51+
* @param string $countryCode
52+
* @param string $vatNumber
53+
*
54+
* @return object
55+
*
56+
* @throws ViesException
57+
*/
58+
public function getInfo(string $countryCode, string $vatNumber): object
4659
{
4760
try {
4861
$response = $this->getClient()->checkVat(
@@ -55,7 +68,7 @@ public function checkVat(string $countryCode, string $vatNumber): bool
5568
throw new ViesException($e->getMessage(), $e->getCode());
5669
}
5770

58-
return (bool) $response->valid;
71+
return $response;
5972
}
6073

6174
/**

tests/Clients/ClientsTest.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,21 @@
22

33
namespace Ibericode\Vat\Tests\Clients;
44

5+
use Ibericode\Vat\Clients\ClientException;
56
use Ibericode\Vat\Clients\IbericodeVatRatesClient;
67
use Ibericode\Vat\Clients\Client;
78
use Ibericode\Vat\Period;
9+
use PHPUnit\Framework\Attributes\DataProvider;
810
use PHPUnit\Framework\TestCase;
911

1012
class ClientsTest extends TestCase
1113
{
1214
/**
1315
* @group remote-http
14-
* @dataProvider clientProvider
16+
* @throws ClientException
1517
*/
16-
public function testClient(Client $client)
18+
#[DataProvider('clientsProvider')]
19+
public function testClient(Client $client): void
1720
{
1821
$data = $client->fetch();
1922
$this->assertIsArray($data);
@@ -22,7 +25,7 @@ public function testClient(Client $client)
2225
$this->assertInstanceOf(Period::class, $data['NL'][0]);
2326
}
2427

25-
public function clientProvider()
28+
public static function clientsProvider(): \Generator
2629
{
2730
yield [new IbericodeVatRatesClient()];
2831
}

tests/CountriesTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99

1010
class CountriesTest extends TestCase
1111
{
12-
public function testIterator()
12+
public function testIterator(): void
1313
{
1414
$countries = new Countries();
1515

1616
$this->assertCount(249, $countries);
1717
}
1818

19-
public function testArrayAccess()
19+
public function testArrayAccess(): void
2020
{
2121
$countries = new Countries();
2222

@@ -27,35 +27,35 @@ public function testArrayAccess()
2727
$countries['FOO'];
2828
}
2929

30-
public function testArrayAccessWithInvalidCountryCode()
30+
public function testArrayAccessWithInvalidCountryCode(): void
3131
{
3232
$countries = new Countries();
3333
$this->expectException(Exception::class);
3434
$countries['FOO'];
3535
}
3636

37-
public function testArrayAccessSetValue()
37+
public function testArrayAccessSetValue(): void
3838
{
3939
$countries = new Countries();
4040
$this->expectException(Exception::class);
4141
$countries['FOO'] = 'bar';
4242
}
4343

44-
public function testArrayAccessUnsetValue()
44+
public function testArrayAccessUnsetValue(): void
4545
{
4646
$countries = new Countries();
4747
$this->expectException(Exception::class);
4848
unset($countries['FOO']);
4949
}
5050

51-
public function testHasCode()
51+
public function testHasCode(): void
5252
{
5353
$countries = new Countries();
5454
$this->assertFalse($countries->hasCountryCode('FOO'));
5555
$this->assertTrue($countries->hasCountryCode('NL'));
5656
}
5757

58-
public function testIsCodeInEU()
58+
public function testIsCodeInEU(): void
5959
{
6060
$countries = new Countries();
6161
$this->assertFalse($countries->isCountryCodeInEU('FOO'));

0 commit comments

Comments
 (0)