All four identifier classes (PeselIdentifier, NipIdentifier, RegonIdentifier, KrsIdentifier) expose the same two methods: isValid() and validate(). Neither ever throws an exception.
validate() returns a SlashLab\Numerik\Result\ValidationResult readonly class.
Property Type Description $isValidbooltrue when validation passed.$failureslist<ValidationFailure>Empty array on success; one or more failures on failure.
Method Return type Description isFailed()boolInverse of $isValid. getFailures()list<ValidationFailure>Returns the failures array. getFirstFailure()ValidationFailure|nullFirst failure, or null if valid. hasFailureReason(ValidationFailureReason $reason)booltrue if any failure matches the given reason.
use SlashLab \ Numerik \ Numerik ;
use SlashLab \ Numerik \ Enums \ ValidationFailureReason ;
$ result = Numerik :: pesel () -> validate ( ' 92060512186 ' );
$ result -> isValid ; // true
$ result -> isFailed (); // false
$ result -> getFirstFailure (); // null
$ result = Numerik :: nip () -> validate ( ' 0000000000 ' );
$ result -> isValid ; // false
$ result -> isFailed (); // true
// Inspect the first (and usually only) failure
$ failure = $ result -> getFirstFailure ();
$ failure -> reason ; // ValidationFailureReason::InvalidFormat
$ failure -> message ; // 'NIP tax office code cannot be 000.'
// Check for a specific reason
$ result -> hasFailureReason ( ValidationFailureReason :: InvalidChecksum ); // false
$ result -> hasFailureReason ( ValidationFailureReason :: InvalidFormat ); // true
Each item in $failures is a SlashLab\Numerik\Result\ValidationFailure readonly class.
Property Type Description $reasonValidationFailureReasonEnum case identifying the failure category. $messagestringHuman-readable description in English.
SlashLab\Numerik\Enums\ValidationFailureReason is a backed string enum.
Case Value Description InvalidLengthinvalid_lengthInput has the wrong number of digits. InvalidCharactersinvalid_charactersUnexpected characters are present after stripping allowed separators. InvalidFormatinvalid_formatCorrect length and characters, but a structural rule is violated (e.g. NIP tax office code 000).
Case Value Description InvalidChecksuminvalid_checksumThe computed checksum does not match the checksum digit.
Case Value Description InvalidDateinvalid_dateThe date encoded inside the identifier is not a real calendar date. FutureDatefuture_dateThe encoded birth date is in the future. InvalidMonthinvalid_monthThe month encoding does not correspond to any known century range.
Case Value Description AllZerosall_zerosAll digits are zero — structurally plausible but semantically invalid. AllSameDigitall_same_digitAll digits are the same non-zero value.
ValidationResult exposes three static constructors used internally and in tests:
ValidationResult :: pass ();
// Failure with a list of failures
new ValidationFailure ( ValidationFailureReason :: InvalidChecksum , ' Checksum mismatch. ' ),
// Failure with a single reason — shorthand
ValidationResult :: failWithReason (
ValidationFailureReason :: InvalidLength ,
' Expected 11 digits, got 10. ' ,