Skip to content

Commit

Permalink
Remove "IdentityCard" in favor of "PolishIdCard"
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
henriquemoody committed May 11, 2019
1 parent f23b3a5 commit c522f62
Show file tree
Hide file tree
Showing 15 changed files with 58 additions and 185 deletions.
4 changes: 2 additions & 2 deletions docs/list-of-rules.md
Expand Up @@ -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)
Expand All @@ -112,6 +111,7 @@
- [Nip](rules/Nip.md)
- [Pesel](rules/Pesel.md)
- [Pis](rules/Pis.md)
- [PolishIdCard](rules/PolishIdCard.md)

## Integrations

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
31 changes: 0 additions & 31 deletions docs/rules/IdentityCard.md

This file was deleted.

2 changes: 1 addition & 1 deletion docs/rules/Nip.md
Expand Up @@ -25,6 +25,6 @@ Version | Description
***
See also:

- [IdentityCard](IdentityCard.md)
- [Pesel](Pesel.md)
- [PolishIdCard](PolishIdCard.md)
- [SubdivisionCode](SubdivisionCode.md)
2 changes: 1 addition & 1 deletion docs/rules/Pesel.md
Expand Up @@ -24,6 +24,6 @@ Version | Description
***
See also:

- [IdentityCard](IdentityCard.md)
- [Nip](Nip.md)
- [PolishIdCard](PolishIdCard.md)
- [SubdivisionCode](SubdivisionCode.md)
29 changes: 29 additions & 0 deletions docs/rules/PolishIdCard.md
@@ -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)
2 changes: 1 addition & 1 deletion docs/rules/SubdivisionCode.md
Expand Up @@ -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"
Expand Down
32 changes: 0 additions & 32 deletions library/Exceptions/IdentityCardException.php

This file was deleted.

Expand Up @@ -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}
Expand Down
11 changes: 2 additions & 9 deletions library/Factory.php
Expand Up @@ -35,15 +35,8 @@
*/
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.
Expand Down
55 changes: 0 additions & 55 deletions library/Rules/AbstractLocaleWrapper.php

This file was deleted.

28 changes: 0 additions & 28 deletions library/Rules/IdentityCard.php

This file was deleted.

Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion library/Validator.php
Expand Up @@ -81,7 +81,6 @@
* @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)
Expand Down Expand Up @@ -136,6 +135,7 @@
* @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()
Expand Down
Expand Up @@ -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

0 comments on commit c522f62

Please sign in to comment.