Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
trippo authored Nov 14, 2023
2 parents 00e0fc2 + 7f18ad4 commit 740b8fe
Show file tree
Hide file tree
Showing 17 changed files with 41 additions and 43 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ jobs:
strategy:
matrix:
php-version:
- "8.0"
- "8.1"
- "8.2"
- "8.3"

steps:
- name: "Checkout"
Expand All @@ -50,8 +50,8 @@ jobs:
php-version: "${{ matrix.php-version }}"

- name: "Install dependencies with Composer"
uses: "ramsey/composer-install@v2"
uses: "ramsey/composer-install@v2"

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

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ibericode/vat
[![Total Downloads](https://img.shields.io/packagist/dt/dannyvankooten/vat.php.svg)](https://packagist.org/packages/ibericode/vat)
![License](https://img.shields.io/github/license/ibericode/vat.svg)

This is a simple PHP library to help you deal with Europe's VAT rules.
This is a simple PHP library to help you deal with Europe's VAT rules.

- Fetch VAT rates for any EU member state using [ibericode/vat-rates](https://github.com/ibericode/vat-rates).
- Validate VAT numbers (by format and/or [existence](http://ec.europa.eu/taxation_customs/vies/))
Expand All @@ -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 7.1 or higher with the CURL and JSON extension is required.
[PHP](https://php.net) version 7.3 or higher with the CURL and JSON extension is required.

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

Expand Down
2 changes: 1 addition & 1 deletion phpcs.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<ruleset name="rules">
<description>rules</description>
<rule ref="PSR2"/>
<rule ref="PSR12"/>
<file>tests/</file>
<file>src/</file>
<arg name="colors"/>
Expand Down
3 changes: 1 addition & 2 deletions src/Clients/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

interface Client
{

/**
* This method should return an associative array in the following format:
*
Expand All @@ -18,5 +17,5 @@ interface Client
* @return array
* @throws ClientException
*/
public function fetch() : array;
public function fetch(): array;
}
5 changes: 3 additions & 2 deletions src/Clients/IbericodeVatRatesClient.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Ibericode\Vat\Clients;
Expand All @@ -12,7 +13,7 @@ class IbericodeVatRatesClient implements Client
*
* @return array
*/
public function fetch() : array
public function fetch(): array
{
$url = 'https://raw.githubusercontent.com/ibericode/vat-rates/master/vat-rates.json';

Expand All @@ -33,7 +34,7 @@ public function fetch() : array
return $this->parseResponse($body);
}

private function parseResponse(string $response_body) : array
private function parseResponse(string $response_body): array
{
$result = json_decode($response_body, true);

Expand Down
7 changes: 4 additions & 3 deletions src/Countries.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Ibericode\Vat;
Expand Down Expand Up @@ -276,15 +277,15 @@ class Countries implements \Iterator, \ArrayAccess
* @param string $code
* @return bool
*/
public function hasCountryCode(string $code) : bool
public function hasCountryCode(string $code): bool
{
return $this->offsetExists($code);
}

/**
* @return array
*/
public function getCountryCodesInEU() : array
public function getCountryCodesInEU(): array
{
return ['AT', 'BE', 'BG', 'CY', 'CZ', 'DE', 'DK', 'EE', 'ES', 'FI', 'FR', 'GR', 'HU', 'HR', 'IE', 'IT', 'LT', 'LU', 'LV', 'MT', 'NL', 'PL', 'PT', 'RO', 'SE', 'SI', 'SK', 'XI'];
}
Expand All @@ -293,7 +294,7 @@ public function getCountryCodesInEU() : array
* @param string $code
* @return bool
*/
public function isCountryCodeInEU(string $code) : bool
public function isCountryCodeInEU(string $code): bool
{
return in_array($code, $this->getCountryCodesInEU(), true);
}
Expand Down
3 changes: 1 addition & 2 deletions src/Geolocation/GeolocatorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@

interface GeolocatorInterface
{

/**
* @param string $ipAddress The IP address to geolocate
* @return string A ISO-3166-1-alpha2 country code or an empty string on failure
*/
public function locateIpAddress(string $ipAddress) : string;
public function locateIpAddress(string $ipAddress): string;
}
3 changes: 1 addition & 2 deletions src/Geolocation/IP2C.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@
*/
class IP2C implements GeolocatorInterface
{

/**
* @param string $ipAddress
* @return string
*/
public function locateIpAddress(string $ipAddress) : string
public function locateIpAddress(string $ipAddress): string
{
if ($ipAddress === '') {
return '';
Expand Down
2 changes: 1 addition & 1 deletion src/Geolocation/IP2Country.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class IP2Country implements GeolocatorInterface
* @param string $ipAddress
* @return string
*/
public function locateIpAddress(string $ipAddress) : string
public function locateIpAddress(string $ipAddress): string
{
if ($ipAddress === '') {
return '';
Expand Down
2 changes: 1 addition & 1 deletion src/Geolocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function __construct(string $service = 'ip2c.org')
$this->service = new $this->services[$service]();
}

public function locateIpAddress(string $ipAddress) : string
public function locateIpAddress(string $ipAddress): string
{
if ($ipAddress === '') {
return '';
Expand Down
2 changes: 1 addition & 1 deletion src/Period.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function __construct(DateTimeInterface $effectiveFrom, array $rates, arra
$this->exceptions = $exceptions;
}

public function getEffectiveFrom() : DateTimeInterface
public function getEffectiveFrom(): DateTimeInterface
{
return $this->effectiveFrom;
}
Expand Down
17 changes: 9 additions & 8 deletions src/Rates.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
<?php

declare(strict_types=1);

namespace Ibericode\Vat;

use DateTime;
use DateTimeInterface;
use DateTimeImmutable;

use Ibericode\Vat\Clients\ClientException;
use Ibericode\Vat\Clients\IbericodeVatRatesClient;
use Ibericode\Vat\Clients\Client;

class Rates
{
const RATE_STANDARD = 'standard';
public const RATE_STANDARD = 'standard';

private $rates = [];

Expand Down Expand Up @@ -46,13 +45,13 @@ public function __construct(string $storagePath, int $refreshInterval = 12 * 360
$this->client = $client;
}

private function load()
private function load(): void
{
if (count($this->rates) > 0) {
return;
}

if ($this->storagePath !== '' && file_exists($this->storagePath)) {
if ($this->storagePath !== '' && \is_file($this->storagePath)) {
$this->loadFromFile();

// bail early if file is still valid
Expand All @@ -65,7 +64,7 @@ private function load()
$this->loadFromRemote();
}

private function loadFromFile()
private function loadFromFile(): void
{
$contents = file_get_contents($this->storagePath);

Expand All @@ -83,7 +82,7 @@ private function loadFromFile()
$this->rates = $data;
}

private function loadFromRemote()
private function loadFromRemote(): void
{
try {
$this->client = $this->client ?: new IbericodeVatRatesClient();
Expand Down Expand Up @@ -111,7 +110,7 @@ private function loadFromRemote()
}
}

private function resolvePeriod(string $countryCode, DateTimeInterface $datetime) : Period
private function resolvePeriod(string $countryCode, DateTimeInterface $datetime): Period
{
$this->load();

Expand All @@ -133,6 +132,7 @@ private function resolvePeriod(string $countryCode, DateTimeInterface $datetime)
/**
* @param string $countryCode ISO-3166-1-alpha2 country code
* @param string $level
* @param ?string $postcode
* @return float
* @throws \Exception
*/
Expand All @@ -146,6 +146,7 @@ public function getRateForCountry(string $countryCode, string $level = self::RAT
* @param string $countryCode ISO-3166-1-alpha2 country code
* @param DateTimeInterface $datetime
* @param string $level
* @param ?string $postcode
* @return float
* @throws Exception
*/
Expand Down
14 changes: 7 additions & 7 deletions src/Validator.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php

declare(strict_types=1);

namespace Ibericode\Vat;

class Validator
{

/**
* Regular expression patterns per country code
*
Expand All @@ -14,7 +14,7 @@ class Validator
*/
private $patterns = [
'AT' => 'U[A-Z\d]{8}',
'BE' => '(0\d{9}|\d{10})',
'BE' => '(0|1)\d{9}',
'BG' => '\d{9,10}',
'CY' => '\d{8}[A-Z]',
'CZ' => '\d{8,10}',
Expand Down Expand Up @@ -67,7 +67,7 @@ public function __construct(Vies\Client $client = null)
* @param string $countryCode
* @return bool
*/
public function validateCountryCode(string $countryCode) : bool
public function validateCountryCode(string $countryCode): bool
{
$countries = new Countries();
return isset($countries[$countryCode]);
Expand All @@ -79,7 +79,7 @@ public function validateCountryCode(string $countryCode) : bool
* @param string $ipAddress
* @return bool
*/
public function validateIpAddress(string $ipAddress) : bool
public function validateIpAddress(string $ipAddress): bool
{
if ($ipAddress === '') {
return false;
Expand All @@ -95,7 +95,7 @@ public function validateIpAddress(string $ipAddress) : bool
*
* @return boolean
*/
public function validateVatNumberFormat(string $vatNumber) : bool
public function validateVatNumberFormat(string $vatNumber): bool
{
if ($vatNumber === '') {
return false;
Expand All @@ -120,7 +120,7 @@ public function validateVatNumberFormat(string $vatNumber) : bool
*
* @throws Vies\ViesException
*/
protected function validateVatNumberExistence(string $vatNumber) : bool
protected function validateVatNumberExistence(string $vatNumber): bool
{
$vatNumber = strtoupper($vatNumber);
$country = substr($vatNumber, 0, 2);
Expand All @@ -137,7 +137,7 @@ protected function validateVatNumberExistence(string $vatNumber) : bool
*
* @throws Vies\ViesException
*/
public function validateVatNumber(string $vatNumber) : bool
public function validateVatNumber(string $vatNumber): bool
{
return $this->validateVatNumberFormat($vatNumber) && $this->validateVatNumberExistence($vatNumber);
}
Expand Down
8 changes: 4 additions & 4 deletions src/Vies/Client.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Ibericode\Vat\Vies;
Expand All @@ -8,11 +9,10 @@

class Client
{

/**
* @const string
*/
const URL = 'https://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl';
private const URL = 'https://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl';

/**
* @var SoapClient
Expand Down Expand Up @@ -42,7 +42,7 @@ public function __construct(int $timeout = 10)
*
* @throws ViesException
*/
public function checkVat(string $countryCode, string $vatNumber) : bool
public function checkVat(string $countryCode, string $vatNumber): bool
{
try {
$response = $this->getClient()->checkVat(
Expand All @@ -61,7 +61,7 @@ public function checkVat(string $countryCode, string $vatNumber) : bool
/**
* @return SoapClient
*/
protected function getClient() : SoapClient
protected function getClient(): SoapClient
{
if ($this->client === null) {
$this->client = new SoapClient(self::URL, ['connection_timeout' => $this->timeout]);
Expand Down
1 change: 0 additions & 1 deletion src/Vies/ViesException.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@

class ViesException extends Exception
{

}
1 change: 0 additions & 1 deletion tests/Clients/ClientsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

class ClientsTest extends TestCase
{

/**
* @group remote-http
* @dataProvider clientProvider
Expand Down
Loading

0 comments on commit 740b8fe

Please sign in to comment.