mirror of
https://github.com/Respect/Validation.git
synced 2024-06-04 23:02:16 +02:00
Remove "IdentityCard" in favor of "PolishIdCard"
The only Identity Card we have is the Polish one, that said it makes more sense to have a specific rule that only validates that, rather than having a "IdentityCard" rule that only accepts one value. Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
This commit is contained in:
parent
f23b3a522a
commit
c522f6235c
|
@ -102,7 +102,6 @@
|
|||
- [Cnh](rules/Cnh.md)
|
||||
- [Cnpj](rules/Cnpj.md)
|
||||
- [Cpf](rules/Cpf.md)
|
||||
- [IdentityCard](rules/IdentityCard.md)
|
||||
- [Imei](rules/Imei.md)
|
||||
- [Isbn](rules/Isbn.md)
|
||||
- [Luhn](rules/Luhn.md)
|
||||
|
@ -112,6 +111,7 @@
|
|||
- [Nip](rules/Nip.md)
|
||||
- [Pesel](rules/Pesel.md)
|
||||
- [Pis](rules/Pis.md)
|
||||
- [PolishIdCard](rules/PolishIdCard.md)
|
||||
|
||||
## Integrations
|
||||
|
||||
|
@ -326,7 +326,6 @@
|
|||
- [HexRgbColor](rules/HexRgbColor.md)
|
||||
- [Iban](rules/Iban.md)
|
||||
- [Identical](rules/Identical.md)
|
||||
- [IdentityCard](rules/IdentityCard.md)
|
||||
- [Image](rules/Image.md)
|
||||
- [Imei](rules/Imei.md)
|
||||
- [In](rules/In.md)
|
||||
|
@ -381,6 +380,7 @@
|
|||
- [Phone](rules/Phone.md)
|
||||
- [PhpLabel](rules/PhpLabel.md)
|
||||
- [Pis](rules/Pis.md)
|
||||
- [PolishIdCard](rules/PolishIdCard.md)
|
||||
- [Positive](rules/Positive.md)
|
||||
- [PostalCode](rules/PostalCode.md)
|
||||
- [PrimeNumber](rules/PrimeNumber.md)
|
||||
|
|
|
@ -1,31 +0,0 @@
|
|||
# IdentityCard
|
||||
|
||||
- `IdentityCard(string $countryCode)`
|
||||
|
||||
Validates Identity Card numbers according to the defined country.
|
||||
|
||||
```php
|
||||
v::identityCard('PL')->validate('AYW036733'); // true
|
||||
v::identityCard('PL')->validate('APH505567'); // true
|
||||
v::identityCard('PL')->validate('APH 505567'); // false
|
||||
v::identityCard('PL')->validate('AYW036731'); // false
|
||||
```
|
||||
|
||||
For now this rule only accepts Polish Identity Card numbers (Dowód Osobisty).
|
||||
|
||||
## Categorization
|
||||
|
||||
- Identifications
|
||||
|
||||
## Changelog
|
||||
|
||||
Version | Description
|
||||
--------|-------------
|
||||
1.1.0 | Created
|
||||
|
||||
***
|
||||
See also:
|
||||
|
||||
- [Nip](Nip.md)
|
||||
- [Pesel](Pesel.md)
|
||||
- [SubdivisionCode](SubdivisionCode.md)
|
|
@ -25,6 +25,6 @@ Version | Description
|
|||
***
|
||||
See also:
|
||||
|
||||
- [IdentityCard](IdentityCard.md)
|
||||
- [Pesel](Pesel.md)
|
||||
- [PolishIdCard](PolishIdCard.md)
|
||||
- [SubdivisionCode](SubdivisionCode.md)
|
||||
|
|
|
@ -24,6 +24,6 @@ Version | Description
|
|||
***
|
||||
See also:
|
||||
|
||||
- [IdentityCard](IdentityCard.md)
|
||||
- [Nip](Nip.md)
|
||||
- [PolishIdCard](PolishIdCard.md)
|
||||
- [SubdivisionCode](SubdivisionCode.md)
|
||||
|
|
29
docs/rules/PolishIdCard.md
Normal file
29
docs/rules/PolishIdCard.md
Normal file
|
@ -0,0 +1,29 @@
|
|||
# PolishIdCard
|
||||
|
||||
- `PolishIdCard()`
|
||||
|
||||
Validates whether the input is a Polish identity card (Dowód Osobisty).
|
||||
|
||||
```php
|
||||
v::polishIdCard()->validate('AYW036733'); // true
|
||||
v::polishIdCard()->validate('APH505567'); // true
|
||||
v::polishIdCard()->validate('APH 505567'); // false
|
||||
v::polishIdCard()->validate('AYW036731'); // false
|
||||
```
|
||||
|
||||
## Categorization
|
||||
|
||||
- Identifications
|
||||
|
||||
## Changelog
|
||||
|
||||
Version | Description
|
||||
--------|-------------
|
||||
2.0.0 | Created
|
||||
|
||||
***
|
||||
See also:
|
||||
|
||||
- [Nip](Nip.md)
|
||||
- [Pesel](Pesel.md)
|
||||
- [SubdivisionCode](SubdivisionCode.md)
|
|
@ -287,10 +287,10 @@ See also:
|
|||
|
||||
- [CountryCode](CountryCode.md)
|
||||
- [CurrencyCode](CurrencyCode.md)
|
||||
- [IdentityCard](IdentityCard.md)
|
||||
- [KeyValue](KeyValue.md)
|
||||
- [Nip](Nip.md)
|
||||
- [Pesel](Pesel.md)
|
||||
- [PolishIdCard](PolishIdCard.md)
|
||||
- [Tld](Tld.md)
|
||||
|
||||
[Creative Commons Attribution 3.0 License]: http://creativecommons.org/licenses/by/3.0 "Creative Commons Attribution 3.0 License"
|
||||
|
|
|
@ -1,32 +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>
|
||||
*/
|
||||
final class IdentityCardException extends ValidationException
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public static $defaultTemplates = [
|
||||
self::MODE_DEFAULT => [
|
||||
self::STANDARD => '{{name}} must be a valid Identity Card number for {{countryCode}}',
|
||||
],
|
||||
self::MODE_NEGATIVE => [
|
||||
self::STANDARD => '{{name}} must not be a valid Identity Card number for {{countryCode}}',
|
||||
],
|
||||
];
|
||||
}
|
|
@ -11,14 +11,12 @@
|
|||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Respect\Validation\Exceptions\Locale;
|
||||
|
||||
use Respect\Validation\Exceptions\ValidationException;
|
||||
namespace Respect\Validation\Exceptions;
|
||||
|
||||
/**
|
||||
* @author Henrique Moody <henriquemoody@gmail.com>
|
||||
*/
|
||||
final class PlIdentityCardException extends ValidationException
|
||||
final class PolishIdCardException extends ValidationException
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
|
@ -35,15 +35,8 @@ use function ucfirst;
|
|||
*/
|
||||
final class Factory
|
||||
{
|
||||
private const DEFAULT_RULES_NAMESPACES = [
|
||||
'Respect\\Validation\\Rules',
|
||||
'Respect\\Validation\\Rules\\Locale',
|
||||
];
|
||||
|
||||
private const DEFAULT_EXCEPTIONS_NAMESPACES = [
|
||||
'Respect\\Validation\\Exceptions',
|
||||
'Respect\\Validation\\Exceptions\\Locale',
|
||||
];
|
||||
private const DEFAULT_RULES_NAMESPACES = ['Respect\\Validation\\Rules'];
|
||||
private const DEFAULT_EXCEPTIONS_NAMESPACES = ['Respect\\Validation\\Exceptions'];
|
||||
|
||||
/**
|
||||
* Default instance of the Factory.
|
||||
|
|
|
@ -1,55 +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\Exceptions\ComponentException;
|
||||
use function class_exists;
|
||||
use function mb_strtolower;
|
||||
use function sprintf;
|
||||
use function ucfirst;
|
||||
|
||||
/**
|
||||
* Abstract class to help creating rules based on location.
|
||||
*
|
||||
* @author Henrique Moody <henriquemoody@gmail.com>
|
||||
*/
|
||||
abstract class AbstractLocaleWrapper extends AbstractWrapper
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $countryCode;
|
||||
|
||||
/**
|
||||
* Initializes the rule.
|
||||
*
|
||||
* @throws ComponentException when country is not supported
|
||||
*/
|
||||
public function __construct(string $countryCode)
|
||||
{
|
||||
$normalized = ucfirst(mb_strtolower($countryCode));
|
||||
$className = sprintf('%s\\Locale\\%s%s', __NAMESPACE__, $normalized, $this->getSuffix());
|
||||
if (!class_exists($className)) {
|
||||
throw new ComponentException(sprintf('"%s" is not a supported country code', $countryCode));
|
||||
}
|
||||
|
||||
$this->countryCode = $countryCode;
|
||||
parent::__construct(new $className());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the class name based on the identifier.
|
||||
*/
|
||||
abstract protected function getSuffix(): string;
|
||||
}
|
|
@ -1,28 +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>
|
||||
*/
|
||||
final class IdentityCard extends AbstractLocaleWrapper
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function getSuffix(): string
|
||||
{
|
||||
return 'IdentityCard';
|
||||
}
|
||||
}
|
|
@ -11,20 +11,19 @@
|
|||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Respect\Validation\Rules\Locale;
|
||||
namespace Respect\Validation\Rules;
|
||||
|
||||
use Respect\Validation\Rules\AbstractRule;
|
||||
use function ord;
|
||||
use function preg_match;
|
||||
|
||||
/**
|
||||
* Validator for Polish identity card.
|
||||
* Validates whether the input is a Polish identity card (Dowód Osobisty).
|
||||
*
|
||||
* @see https://en.wikipedia.org/wiki/Polish_identity_card
|
||||
*
|
||||
* @author Henrique Moody <henriquemoody@gmail.com>
|
||||
*/
|
||||
final class PlIdentityCard extends AbstractRule
|
||||
final class PolishIdCard extends AbstractRule
|
||||
{
|
||||
private const ASCII_CODE_0 = 48;
|
||||
private const ASCII_CODE_7 = 55;
|
|
@ -81,7 +81,6 @@ use function count;
|
|||
* @method static Validator hexRgbColor()
|
||||
* @method static Validator iban()
|
||||
* @method static Validator identical($value)
|
||||
* @method static Validator identityCard(string $countryCode)
|
||||
* @method static Validator image(finfo $fileInfo = null)
|
||||
* @method static Validator imei()
|
||||
* @method static Validator in($haystack, bool $compareIdentical = false)
|
||||
|
@ -136,6 +135,7 @@ use function count;
|
|||
* @method static Validator phone()
|
||||
* @method static Validator phpLabel()
|
||||
* @method static Validator pis()
|
||||
* @method static Validator polishIdCard()
|
||||
* @method static Validator positive()
|
||||
* @method static Validator postalCode(string $countryCode)
|
||||
* @method static Validator primeNumber()
|
||||
|
|
|
@ -7,37 +7,36 @@ declare(strict_types=1);
|
|||
|
||||
require_once 'vendor/autoload.php';
|
||||
|
||||
use Respect\Validation\Exceptions\IdentityCardException;
|
||||
use Respect\Validation\Exceptions\Locale\PlIdentityCardException;
|
||||
use Respect\Validation\Exceptions\NestedValidationException;
|
||||
use Respect\Validation\Exceptions\PolishIdCardException;
|
||||
use Respect\Validation\Validator as v;
|
||||
|
||||
try {
|
||||
v::identityCard('PL')->check('AYE205411');
|
||||
} catch (PlIdentityCardException $exception) {
|
||||
v::polishIdCard()->check('AYE205411');
|
||||
} catch (PolishIdCardException $exception) {
|
||||
echo $exception->getMessage().PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
v::not(v::identityCard('PL'))->check('AYE205410');
|
||||
} catch (IdentityCardException $exception) {
|
||||
v::not(v::polishIdCard())->check('AYE205410');
|
||||
} catch (PolishIdCardException $exception) {
|
||||
echo $exception->getMessage().PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
v::identityCard('PL')->assert('AYE205411');
|
||||
v::polishIdCard()->assert('AYE205411');
|
||||
} catch (NestedValidationException $exception) {
|
||||
echo $exception->getFullMessage().PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
v::not(v::identityCard('PL'))->assert('AYE205410');
|
||||
v::not(v::polishIdCard())->assert('AYE205410');
|
||||
} catch (NestedValidationException $exception) {
|
||||
echo $exception->getFullMessage().PHP_EOL;
|
||||
}
|
||||
?>
|
||||
--EXPECT--
|
||||
"AYE205411" must be a valid Polish Identity Card number
|
||||
"AYE205410" must not be a valid Identity Card number for "PL"
|
||||
"AYE205410" must not be a valid Polish Identity Card number
|
||||
- "AYE205411" must be a valid Polish Identity Card number
|
||||
- "AYE205410" must not be a valid Identity Card number for "PL"
|
||||
- "AYE205410" must not be a valid Polish Identity Card number
|
|
@ -11,24 +11,25 @@
|
|||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Respect\Validation\Rules\Locale;
|
||||
namespace Respect\Validation\Rules;
|
||||
|
||||
use Respect\Validation\Test\RuleTestCase;
|
||||
|
||||
/**
|
||||
* @group rule
|
||||
* @covers \Respect\Validation\Rules\Locale\PlIdentityCard
|
||||
* @group rule
|
||||
*
|
||||
* @covers \Respect\Validation\Rules\PolishIdCard
|
||||
*
|
||||
* @author Henrique Moody <henriquemoody@gmail.com>
|
||||
*/
|
||||
final class PlIdentityCardTest extends RuleTestCase
|
||||
final class PolishIdCardTest extends RuleTestCase
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function providerForValidInput(): array
|
||||
{
|
||||
$rule = new PlIdentityCard();
|
||||
$rule = new PolishIdCard();
|
||||
|
||||
return [
|
||||
[$rule, 'APH505567'],
|
||||
|
@ -42,7 +43,7 @@ final class PlIdentityCardTest extends RuleTestCase
|
|||
*/
|
||||
public function providerForInvalidInput(): array
|
||||
{
|
||||
$rule = new PlIdentityCard();
|
||||
$rule = new PolishIdCard();
|
||||
|
||||
return [
|
||||
[$rule, 'AAAAAAAAA'],
|
Loading…
Reference in a new issue