Remove "Vatin" in favor of "Nip"

There are not other VATINs besides the one from Poland. That said, it
makes more sense to have a specific rule that only validates NIP.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
This commit is contained in:
Henrique Moody 2019-05-11 23:40:52 +02:00
parent 0417fea213
commit f23b3a522a
No known key found for this signature in database
GPG key ID: 221E9281655813A6
15 changed files with 60 additions and 203 deletions

View file

@ -109,9 +109,9 @@
- [MacAddress](rules/MacAddress.md)
- [NfeAccessKey](rules/NfeAccessKey.md)
- [Nif](rules/Nif.md)
- [Nip](rules/Nip.md)
- [Pesel](rules/Pesel.md)
- [Pis](rules/Pis.md)
- [Vatin](rules/Vatin.md)
## Integrations
@ -207,10 +207,10 @@
- [Alpha](rules/Alpha.md)
- [Base64](rules/Base64.md)
- [Charset](rules/Charset.md)
- [Control](rules/Control.md)
- [Consonant](rules/Consonant.md)
- [Contains](rules/Contains.md)
- [ContainsAny](rules/ContainsAny.md)
- [Control](rules/Control.md)
- [Digit](rules/Digit.md)
- [EndsWith](rules/EndsWith.md)
- [Graph](rules/Graph.md)
@ -290,10 +290,10 @@
- [Charset](rules/Charset.md)
- [Cnh](rules/Cnh.md)
- [Cnpj](rules/Cnpj.md)
- [Control](rules/Control.md)
- [Consonant](rules/Consonant.md)
- [Contains](rules/Contains.md)
- [ContainsAny](rules/ContainsAny.md)
- [Control](rules/Control.md)
- [Countable](rules/Countable.md)
- [CountryCode](rules/CountryCode.md)
- [Cpf](rules/Cpf.md)
@ -359,6 +359,7 @@
- [Negative](rules/Negative.md)
- [NfeAccessKey](rules/NfeAccessKey.md)
- [Nif](rules/Nif.md)
- [Nip](rules/Nip.md)
- [No](rules/No.md)
- [NoWhitespace](rules/NoWhitespace.md)
- [NoneOf](rules/NoneOf.md)
@ -410,7 +411,6 @@
- [Uppercase](rules/Uppercase.md)
- [Url](rules/Url.md)
- [Uuid](rules/Uuid.md)
- [Vatin](rules/Vatin.md)
- [Version](rules/Version.md)
- [VideoUrl](rules/VideoUrl.md)
- [Vowel](rules/Vowel.md)

View file

@ -42,8 +42,8 @@ See also:
- [Alpha](Alpha.md)
- [Charset](Charset.md)
- [Control](Control.md)
- [Consonant](Consonant.md)
- [Control](Control.md)
- [Digit](Digit.md)
- [Lowercase](Lowercase.md)
- [NoWhitespace](NoWhitespace.md)

View file

@ -26,6 +26,6 @@ Version | Description
***
See also:
- [Nip](Nip.md)
- [Pesel](Pesel.md)
- [SubdivisionCode](SubdivisionCode.md)
- [Vatin](Vatin.md)

30
docs/rules/Nip.md Normal file
View file

@ -0,0 +1,30 @@
# Nip
- `Nip(string $countryCode)`
Validates whether the input is a Polish VAT identification number (NIP).
```php
v::nip()->validate('1645865777'); // true
v::nip()->validate('1645865778'); // false
v::nip()->validate('1234567890'); // false
v::nip()->validate('164-586-57-77'); // false
v::nip()->validate('164-58-65-777'); // false
```
## Categorization
- Identifications
## Changelog
Version | Description
--------|-------------
2.0.0 | Created
***
See also:
- [IdentityCard](IdentityCard.md)
- [Pesel](Pesel.md)
- [SubdivisionCode](SubdivisionCode.md)

View file

@ -25,5 +25,5 @@ Version | Description
See also:
- [IdentityCard](IdentityCard.md)
- [Nip](Nip.md)
- [SubdivisionCode](SubdivisionCode.md)
- [Vatin](Vatin.md)

View file

@ -289,9 +289,9 @@ See also:
- [CurrencyCode](CurrencyCode.md)
- [IdentityCard](IdentityCard.md)
- [KeyValue](KeyValue.md)
- [Nip](Nip.md)
- [Pesel](Pesel.md)
- [Tld](Tld.md)
- [Vatin](Vatin.md)
[Creative Commons Attribution 3.0 License]: http://creativecommons.org/licenses/by/3.0 "Creative Commons Attribution 3.0 License"
[GeoNames]: http://www.geonames.org "GetNames"

View file

@ -1,32 +0,0 @@
# Vatin
- `Vatin(string $countryCode)`
Validates VAT identification number according to the defined country.
```php
v::vatin('PL')->validate('1645865777'); // true
v::vatin('PL')->validate('1645865778'); // false
v::vatin('PL')->validate('1234567890'); // false
v::vatin('PL')->validate('164-586-57-77'); // false
v::vatin('PL')->validate('164-58-65-777'); // false
```
For now this rule only accepts Polish VAT identification number (NIP).
## Categorization
- Identifications
## Changelog
Version | Description
--------|-------------
2.0.0 | Created
***
See also:
- [IdentityCard](IdentityCard.md)
- [Pesel](Pesel.md)
- [SubdivisionCode](SubdivisionCode.md)

View file

@ -11,15 +11,13 @@
declare(strict_types=1);
namespace Respect\Validation\Exceptions\Locale;
use Respect\Validation\Exceptions\ValidationException;
namespace Respect\Validation\Exceptions;
/**
* @author Henrique Moody <henriquemoody@gmail.com>
* @author Tomasz Regdos <tomek@regdos.com>
*/
final class PlVatinException extends ValidationException
final class NipException extends ValidationException
{
/**
* {@inheritDoc}

View file

@ -1,33 +0,0 @@
<?php
/*
* This file is part of Respect/Validation.
*
* (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
*
* For the full copyright and license information, please view the "LICENSE.md"
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Henrique Moody <henriquemoody@gmail.com>
* @author Tomasz Regdos <tomek@regdos.com>
*/
final class VatinException extends ValidationException
{
/**
* {@inheritDoc}
*/
public static $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must be a valid VAT identification number for {{countryCode}}',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} must not be a valid VAT identification number for {{countryCode}}',
],
];
}

View file

@ -11,23 +11,22 @@
declare(strict_types=1);
namespace Respect\Validation\Rules\Locale;
namespace Respect\Validation\Rules;
use Respect\Validation\Rules\AbstractRule;
use function array_map;
use function is_scalar;
use function preg_match;
use function str_split;
/**
* Validator for Polish VAT identification number (NIP).
* Validates whether the input is a Polish VAT identification number (NIP).
*
* @see https://en.wikipedia.org/wiki/VAT_identification_number
*
* @author Henrique Moody <henriquemoody@gmail.com>
* @author Tomasz Regdos <tomek@regdos.com>
*/
final class PlVatin extends AbstractRule
final class Nip extends AbstractRule
{
/**
* {@inheritDoc}

View file

@ -1,29 +0,0 @@
<?php
/*
* This file is part of Respect/Validation.
*
* (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
*
* For the full copyright and license information, please view the "LICENSE.md"
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Respect\Validation\Rules;
/**
* @author Henrique Moody <henriquemoody@gmail.com>
* @author Tomasz Regdos <tomek@regdos.com>
*/
final class Vatin extends AbstractLocaleWrapper
{
/**
* {@inheritDoc}
*/
protected function getSuffix(): string
{
return 'Vatin';
}
}

View file

@ -114,6 +114,7 @@ use function count;
* @method static Validator negative()
* @method static Validator nfeAccessKey()
* @method static Validator nif()
* @method static Validator nip()
* @method static Validator no($useLocale = false)
* @method static Validator noneOf(Validatable ...$rule)
* @method static Validator not(Validatable $rule)
@ -165,7 +166,6 @@ use function count;
* @method static Validator uppercase()
* @method static Validator url()
* @method static Validator uuid(int $version = null)
* @method static Validator vatin(string $countryCode)
* @method static Validator version()
* @method static Validator videoUrl(string $service = null)
* @method static Validator vowel(string ...$additionalChars)

View file

@ -8,37 +8,36 @@ declare(strict_types=1);
require_once 'vendor/autoload.php';
use Respect\Validation\Exceptions\Locale\PlVatinException;
use Respect\Validation\Exceptions\NestedValidationException;
use Respect\Validation\Exceptions\VatinException;
use Respect\Validation\Exceptions\NipException;
use Respect\Validation\Validator as v;
try {
v::vatin('PL')->check('1645865778');
} catch (PlVatinException $exception) {
v::nip()->check('1645865778');
} catch (NipException $exception) {
echo $exception->getMessage().PHP_EOL;
}
try {
v::not(v::vatin('PL'))->check('1645865777');
} catch (VatinException $exception) {
v::not(v::nip())->check('1645865777');
} catch (NipException $exception) {
echo $exception->getMessage().PHP_EOL;
}
try {
v::vatin('PL')->assert('1645865778');
v::nip()->assert('1645865778');
} catch (NestedValidationException $exception) {
echo $exception->getFullMessage().PHP_EOL;
}
try {
v::not(v::vatin('PL'))->assert('1645865777');
v::not(v::nip())->assert('1645865777');
} catch (NestedValidationException $exception) {
echo $exception->getFullMessage().PHP_EOL;
}
?>
--EXPECT--
"1645865778" must be a valid Polish VAT identification number
"1645865777" must not be a valid VAT identification number for "PL"
"1645865777" must not be a valid Polish VAT identification number
- "1645865778" must be a valid Polish VAT identification number
- "1645865777" must not be a valid VAT identification number for "PL"
- "1645865777" must not be a valid Polish VAT identification number

View file

@ -11,26 +11,27 @@
declare(strict_types=1);
namespace Respect\Validation\Rules\Locale;
namespace Respect\Validation\Rules;
use Respect\Validation\Test\RuleTestCase;
use stdClass;
/**
* @group rule
* @covers \Respect\Validation\Rules\Locale\PlVatin
* @group rule
*
* @covers \Respect\Validation\Rules\Nip
*
* @author Henrique Moody <henriquemoody@gmail.com>
* @author Tomasz Regdos <tomek@regdos.com>
*/
final class PlVatinTest extends RuleTestCase
final class NipTest extends RuleTestCase
{
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
{
$rule = new PlVatin();
$rule = new Nip();
return [
[$rule, '1645865777'],
@ -44,7 +45,7 @@ final class PlVatinTest extends RuleTestCase
*/
public function providerForInvalidInput(): array
{
$rule = new PlVatin();
$rule = new Nip();
return [
[$rule, []],

View file

@ -1,76 +0,0 @@
<?php
/*
* This file is part of Respect/Validation.
*
* (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
*
* For the full copyright and license information, please view the "LICENSE.md"
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Respect\Validation\Rules;
use Respect\Validation\Test\RuleTestCase;
use stdClass;
/**
* @group rule
*
* @covers \Respect\Validation\Rules\Vatin
*
* @author Danilo Correa <danilosilva87@gmail.com>
* @author Gabriel Caruso <carusogabriel34@gmail.com>
* @author Henrique Moody <henriquemoody@gmail.com>
* @author Tomasz Regdos <tomek@regdos.com>
*/
final class VatinTest extends RuleTestCase
{
/**
* {@inheritDoc}
*/
public function providerForValidInput(): array
{
$countryCode = 'PL';
$rule = new Vatin($countryCode);
return [
[$rule, '1645865777'],
[$rule, '5581418257'],
[$rule, '1298727531'],
];
}
/**
* {@inheritDoc}
*/
public function providerForInvalidInput(): array
{
$countryCode = 'PL';
$rule = new Vatin($countryCode);
return [
[$rule, []],
[$rule, new stdClass()],
[$rule, '1645865778'],
[$rule, '164-586-57-77'],
[$rule, '164-58-65-777'],
[$rule, '5581418258'],
[$rule, '1298727532'],
[$rule, '1234567890'],
];
}
/**
* @expectedException \Respect\Validation\Exceptions\ComponentException
* @expectedExceptionMessage "BR" is not a supported country code
*
* @test
*/
public function shouldThrowAnExceptionWhenCountryCodeIsNotSupported(): void
{
new Vatin('BR');
}
}