byrokrat/checkdigit

Helper classes to calculate and validate ckecksums

2.0.0 2017-12-05 21:00 UTC

README

Packagist Version Build Status Quality Score Scrutinizer Coverage Dependency Status

Helper classes to calculate and validate ckecksums.

Installation

composer require byrokrat/checkdigit:^2

Requires the bcmath extension.

API

The Calculator interface defines two methods:

  • isValid(string $number): bool checks if number contains a valid check digit.
  • calculateCheckDigit(string $number): string calculates the check digit for number.

Implementations include:

  • Modulo10 and Luhn for modulo 10 check digits (Luhn is simply a shorthand for Modulo10).
  • Modulo11 for modulo 11 check digits.
  • Modulo97 for modulo 97 check digits.

Usage

$luhn = new byrokrat\checkdigit\Luhn;

// outputs '1' (true)
echo $luhn->isValid('55555551');

// outputs '' (false)
echo $luhn->isValid('55555550');

// outputs '1'
echo $luhn->calculateCheckDigit('5555555');