Componette

Componette

nepada

nepada / birth-number v1.2.1

Czech birth number value object.

download-cloud-line composer require nepada/birth-number

Czech birth number value object

Build Status Coverage Status Downloads this Month Latest stable

Installation

Via Composer:

$ composer require nepada/birth-number

Usage

Creating value object

The parser is quite benevolent with regard to the delimiter separating the ending of birth number.

$birthNumber = Nepada\BirthNumber\BirthNumber::fromString('0421010030');
$birthNumber = Nepada\BirthNumber\BirthNumber::fromString('042101/0030');
$birthNumber = Nepada\BirthNumber\BirthNumber::fromString('042101 0030');
$birthNumber = Nepada\BirthNumber\BirthNumber::fromString('042101 / 0030');

Nepada\BirthNumber\InvalidBirthNumberException is thrown in case of invalid input value.

Converting back to string

echo((string) $birthNumber); // '042101/0030'
echo($birthNumber->toString()); // '042101/0030'
echo($birthNumber->toStringWithoutSlash()); // '0421010030'

Validation

Nepada\BirthNumber\BirthNumber::isValid('0421010030'); // true
Nepada\BirthNumber\BirthNumber::isValid('9999999999'); // false

Comparison

$birthNumber1 = Nepada\BirthNumber\BirthNumber::fromString('042101/0030');
$birthNumber2 = Nepada\BirthNumber\BirthNumber::fromString('042101/0030');
$birthNumber1->equals($birthNumber2); // true

Extracting information from birth number

$birthNumber = Nepada\BirthNumber\BirthNumber::fromString('047101 / 0090');
$birthNumber->getBirthDate(); // \DateTimeImmutable('2004-01-01')

$gender = $birthNumber->getGender(); // Nepada\BirthNumber\Gender enum instance
$gender->isFemale(); // true
$gender->isMale(); // false
$gender->toString(); // 'female'

Integrations

  • v1.2.1 1.2.1

    • PHP 8.4 compatibility
  • v1.2.0 1.2.0

    • Drop support for PHP <8.1
    • Convert Gender to native enum (possible BC break: magic __toString() removed)
    • BirthNumber properties marked readonly
    • Drop useless annotations
    • PHP 8.3 compatibility
  • v1.1.2 1.1.2

    • Support nette/utils 4
  • v1.1.1 1.1.1

    • PHP 8.2 compatibility
  • v1.1.0 1.1.0

    • PHP 8.1 compatibility.
  • v1.0.1 1.0.1

    • Compatible with PHP 8.0.
  • v1.0.0 1.0.0

    • Initial release.
price-tag-2-line

Badges

guide-fill

Dependencies

php (>=7.4.0)
nette/utils (^3.0@dev)
Componette Componette felix@nette.org