Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .github/workflows/code_checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# .github/workflows/code_checks.yaml
name: Code_Checks

on: ["push", "pull_request"]

jobs:
tests:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php: ['7.2', '7.3', '7.4', '8.0', '8.1']
stability: [ prefer-lowest, prefer-stable ]

name: PHP ${{ matrix.php }} - ${{ matrix.stability }} tests
steps:
# basically git clone
- uses: actions/checkout@v2

- name: Cache dependencies
uses: actions/cache@v1
with:
path: ~/.composer/cache/files
key: dependencies-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}

# use PHP of specific version
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: pcov
coverage: pcov

- name: Install dependencies
run: composer update --${{ matrix.stability }} --prefer-dist --no-interaction

- name: Execute tests
run: vendor/bin/phpunit --verbose
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
vendor/
composer.lock
composer.lock
.idea/
.phpunit.result.cache
composer.phar
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
language: php

php:
- 5.6
- 7.0
- 7.1
- 7.2
- 7.3
- 7.4
- 8.0

cache:
directories:
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
VATIN
=====
[![Code_Checks](https://github.com/ddeboer/vatin/actions/workflows/code_checks.yml/badge.svg)](https://github.com/ddeboer/vatin/actions/workflows/code_checks.yml)

[![Build Status](https://travis-ci.org/ddeboer/vatin.svg?branch=master)](https://travis-ci.org/ddeboer/vatin)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/ddeboer/vatin/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/ddeboer/vatin/?branch=master)
[![Code Coverage](https://scrutinizer-ci.com/g/ddeboer/vatin/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/ddeboer/vatin/?branch=master)
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
}
],
"require": {
"php": ">=5.6.0"
"php": "^7.2 || ^8.0"
},
"require-dev": {
"ext-soap": "*",
"phpunit/phpunit": "^5.7 || ^6.5"
"phpunit/phpunit": "^8.5.21 || ^9.5"
},
"suggest": {
"ext-soap": "Required if you want to check the VAT number via VIES"
Expand Down
13 changes: 12 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory suffix=".php">./src</directory>
</include>
</coverage>

<phpunit bootstrap="vendor/autoload.php" colors="true">
<testsuites>
<testsuite name="Ddeboer Vatin Test Suite">
<directory suffix="Test.php">./tests/</directory>
Expand Down
25 changes: 7 additions & 18 deletions src/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/**
* Validate a VAT identification number (VATIN)
*
* @link http://en.wikipedia.org/wiki/VAT_identification_number
* @link https://en.wikipedia.org/wiki/VAT_identification_number
* @link http://sima.cat/nif.php
* @link https://github.com/jonathanmaron/zf2_proposal/blob/master/library/Zend/Validator/Vatin.php
*/
Expand All @@ -18,7 +18,7 @@ class Validator
* Regular expression patterns per country code
*
* @var array
* @link http://ec.europa.eu/taxation_customs/vies/faq.html?locale=lt#item_11
* @link https://ec.europa.eu/taxation_customs/vies/faq.html?locale=lt#item_11
*/
private $patterns = array(
'AT' => 'U[A-Z\d]{8}',
Expand Down Expand Up @@ -74,15 +74,10 @@ public function __construct(Client $viesClient = null)
* Returns true if value is a valid VAT identification number, false
* otherwise
*
* @param string $value Value
* @param bool $checkExistence In addition to checking the VATIN's format
* for validity, also check whether the VATIN
* exists. This requires a call to the VIES
* web service.
*
* @return bool
* Optional: In addition to checking the VATIN's format for validity, also check whether the VATIN exists.
* This requires a call to the VIES web service (needs SOAP-Ext).
*/
public function isValid($value, $checkExistence = false)
public function isValid(?string $value, bool $checkExistence = false): bool
{
if (null === $value || '' === $value) {
return false;
Expand Down Expand Up @@ -110,22 +105,16 @@ public function isValid($value, $checkExistence = false)

/**
* Returns true if value is valid country code, false otherwise
*
* @param string $value Value
*
* @return bool
*/
private function isValidCountryCode($value)
private function isValidCountryCode(string $value): bool
{
return isset($this->patterns[$value]);
}

/**
* Get VIES client
*
* @return Client
*/
private function getViesClient()
private function getViesClient(): Client
{
if ($this->viesClient === null) {
$this->viesClient = new Client();
Expand Down
22 changes: 5 additions & 17 deletions src/Vies/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,8 @@ class Client
'checkVatResponse' => 'Ddeboer\Vatin\Vies\Response\CheckVatResponse'
];

/**
* Constructor
*
* @param string|null $wsdl URL to WSDL
*/
public function __construct($wsdl = null)

public function __construct(?string $wsdl = null)
{
if ($wsdl) {
$this->wsdl = $wsdl;
Expand All @@ -48,13 +44,9 @@ public function __construct($wsdl = null)
/**
* Check VAT
*
* @param string $countryCode Country code
* @param string $vatNumber VAT number
*
* @return Response\CheckVatResponse
* @throws ViesException
*/
public function checkVat($countryCode, $vatNumber)
public function checkVat(string $countryCode, string $vatNumber): Response\CheckVatResponse
{
try {
return $this->getSoapClient()->checkVat(
Expand All @@ -68,12 +60,8 @@ public function checkVat($countryCode, $vatNumber)
}
}

/**
* Get SOAP client
*
* @return \SoapClient
*/
private function getSoapClient()

private function getSoapClient(): \SoapClient
{
if (null === $this->soapClient) {
$this->soapClient = new \SoapClient(
Expand Down
2 changes: 1 addition & 1 deletion src/Vies/Response/CheckVatResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function getVatNumber()
return $this->vatNumber;
}

public function getRequestDate()
public function getRequestDate(): \DateTime
{
if (!$this->requestDate instanceof \DateTime) {
$this->requestDate = new \DateTime($this->requestDate);
Expand Down
22 changes: 5 additions & 17 deletions tests/ValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ValidatorTest extends TestCase
{
private $validator;

public function setUp()
public function setUp(): void
{
$this->validator = new Validator();
}
Expand Down Expand Up @@ -58,19 +58,14 @@ public function testInvalidWithVies()
$this->assertFalse($this->validator->isValid('NL123456789B01', true));
}

/**
* @expectedException \Ddeboer\Vatin\Exception\ViesException
*/
public function testWrongConnectionThrowsException()
{
$this->expectException(\Ddeboer\Vatin\Exception\ViesException::class);
$this->validator = new Validator(new Client('meh'));
$this->validator->isValid('NL002065538B01', true);
}

/**
* @return array
*/
public function getValidVatins()
public function getValidVatins(): array
{
return array(
// Examples from Wikipedia (https://en.wikipedia.org/wiki/VAT_identification_number)
Expand Down Expand Up @@ -153,10 +148,7 @@ public function getValidVatins()
);
}

/**
* @return array
*/
public function getInvalidVatins()
public function getInvalidVatins(): array
{
return array(
array(null),
Expand All @@ -169,10 +161,7 @@ public function getInvalidVatins()
);
}

/**
* @return \Ddeboer\Vatin\Vies\Client
*/
private function getViesClientMock()
private function getViesClientMock(): Client
{
return $this->getMockBuilder('\Ddeboer\Vatin\Vies\Client')
->disableOriginalConstructor()
Expand All @@ -191,5 +180,4 @@ private function getCheckVatResponseMock($valid)

return $mock;
}

}