sandwave-io / vat
European VAT rates and number validation.
Installs: 3 499
Dependents: 0
Suggesters: 0
Security: 0
Stars: 11
Watchers: 8
Forks: 4
Open Issues: 0
Requires
- php: ^8.1
- ext-soap: *
- divineomega/php-countries: ^2.3
- psr/simple-cache: ^1.0
Requires (Dev)
- ergebnis/phpstan-rules: ^1.0.0
- friendsofphp/php-cs-fixer: ^3.14.4
- phpstan/phpstan: ^1.10.6
- phpstan/phpstan-deprecation-rules: ^1.1.2
- phpstan/phpstan-phpunit: ^1.3.10
- phpstan/phpstan-strict-rules: ^1.5.0
- phpunit/phpunit: ^10.0.15
- sandwave-io/php-cs-fixer-config: ^1.0.0
README
European VAT utility for PHP
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