From d575f4627ac9d1b2aba782ae0753a72ccd8613c2 Mon Sep 17 00:00:00 2001 From: Christopher Georg Date: Sun, 3 Oct 2021 10:26:18 +0200 Subject: [PATCH 1/2] feat: bump to php 7.2 minimum, add github checks --- .github/workflows/code_checks.yml | 37 ++++++++++++++++++++++++++ .gitignore | 5 +++- .travis.yml | 4 +-- composer.json | 4 +-- phpunit.xml.dist | 13 ++++++++- src/Validator.php | 25 +++++------------ src/Vies/Client.php | 22 ++++----------- src/Vies/Response/CheckVatResponse.php | 2 +- tests/ValidatorTest.php | 22 ++++----------- 9 files changed, 74 insertions(+), 60 deletions(-) create mode 100644 .github/workflows/code_checks.yml diff --git a/.github/workflows/code_checks.yml b/.github/workflows/code_checks.yml new file mode 100644 index 0000000..e9e6c58 --- /dev/null +++ b/.github/workflows/code_checks.yml @@ -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 diff --git a/.gitignore b/.gitignore index 4f4acd3..66fed4c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ vendor/ -composer.lock \ No newline at end of file +composer.lock +.idea/ +.phpunit.result.cache +composer.phar \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index a792ef4..47ddcfb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,12 +1,10 @@ language: php php: - - 5.6 - - 7.0 - - 7.1 - 7.2 - 7.3 - 7.4 + - 8.0 cache: directories: diff --git a/composer.json b/composer.json index 3a3c084..94ca424 100644 --- a/composer.json +++ b/composer.json @@ -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" diff --git a/phpunit.xml.dist b/phpunit.xml.dist index f2bf738..1eb98bd 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,6 +1,17 @@ + + + + ./src + + - ./tests/ diff --git a/src/Validator.php b/src/Validator.php index 0afe7f2..09bffc0 100644 --- a/src/Validator.php +++ b/src/Validator.php @@ -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 */ @@ -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}', @@ -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; @@ -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(); diff --git a/src/Vies/Client.php b/src/Vies/Client.php index 2b534d1..d0c4ea2 100644 --- a/src/Vies/Client.php +++ b/src/Vies/Client.php @@ -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; @@ -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( @@ -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( diff --git a/src/Vies/Response/CheckVatResponse.php b/src/Vies/Response/CheckVatResponse.php index 9660533..41f5d0e 100644 --- a/src/Vies/Response/CheckVatResponse.php +++ b/src/Vies/Response/CheckVatResponse.php @@ -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); diff --git a/tests/ValidatorTest.php b/tests/ValidatorTest.php index e455e5d..79ac280 100644 --- a/tests/ValidatorTest.php +++ b/tests/ValidatorTest.php @@ -11,7 +11,7 @@ class ValidatorTest extends TestCase { private $validator; - public function setUp() + public function setUp(): void { $this->validator = new Validator(); } @@ -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) @@ -153,10 +148,7 @@ public function getValidVatins() ); } - /** - * @return array - */ - public function getInvalidVatins() + public function getInvalidVatins(): array { return array( array(null), @@ -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() @@ -191,5 +180,4 @@ private function getCheckVatResponseMock($valid) return $mock; } - } From 4556e1f442d2314039fc9d1cfe150c48a0e7b806 Mon Sep 17 00:00:00 2001 From: Christopher Georg Date: Sun, 3 Oct 2021 10:27:57 +0200 Subject: [PATCH 2/2] feat: add github actions badge --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 09bab00..acf0346 100644 --- a/README.md +++ b/README.md @@ -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)