composer require sandwave-io/vat
$vatService = new \SandwaveIo\Vat\Vat;
$vatService->validateEuropeanVatNumber("YOURVATNUMBERHERE", "COUNTRYCODE"); // true
$vatService->countryInEurope('NL'); // true
$vatService->europeanVatRate("YOURVATNUMBERHERE"); // 0.0
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);
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.
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