European VAT rates and number validation.

1.1.0 2023-03-13 11:49 UTC

This package is auto-updated.

Last update: 2024-04-09 10:31:14 UTC


README

European VAT utility for PHP

codecov GitHub Workflow Status Packagist PHP Version Support Packagist PHP Version Support Packagist Downloads

Usage

composer require sandwave-io/vat
$vatService = new \SandwaveIo\Vat\Vat;

$vatService->validateEuropeanVatNumber("YOURVATNUMBERHERE", "COUNTRYCODE"); // true

$vatService->countryInEurope('NL'); // true

$vatService->europeanVatRate("YOURVATNUMBERHERE"); // 0.0

Caching

If you resolve VAT rates for a country quite often, it can be a little slow. If you want to, you can cache the results by passing a Psr\SimpleCache\CacheInterface to the Vat() service. The implementation might differ based on your application, but all major frameworks implement this interface on their cache.

/** @var Psr\SimpleCache\CacheInterface $cache */

$vatService = new \SandwaveIo\Vat\Vat(cache: $cache);

External documentation

How to contribute

Feel free to create a PR if you have any ideas for improvements. Or create an issue.

  • When adding code, make sure to add tests for it (phpunit).
  • Make sure the code adheres to our coding standards (use php-cs-fixer to check/fix).
  • Also make sure PHPStan does not find any bugs.
vendor/bin/php-cs-fixer fix

vendor/bin/phpstan analyze

vendor/bin/phpunit --coverage-text

These tools will also run in GitHub actions on PR's and pushes on master.

About the testsuite

There is also an integration test, in order to skip this (heavy) test, run:

vendor/bin/phpunit --exclude=large

We generate coverage in PHPUnit. On the CI we use XDebug to do that. If you have XDebug installed, you can run:

vendor/bin/phpunit --coverage-text

# or generate an interactive report.
vendor/bin/phpunit --coverage-html=coverage_report

Alternatively, you can use PHPDBG as coverage driver:

phpdbg -qrr vendor/bin/phpunit --coverage-text