byrokrat / checkdigit
Helper classes to calculate and validate ckecksums
Installs: 179 951
Dependents: 3
Suggesters: 1
Security: 0
Stars: 9
Watchers: 1
Forks: 3
Open Issues: 0
Requires
- php: >=7.0
- ext-bcmath: *
This package is auto-updated.
Last update: 2021-01-03 22:30:27 UTC
README
ABANDONED! This package is discontinued and will not be updated.
Checkdigit
Helper classes to calculate and validate ckecksums.
Installation
composer require byrokrat/checkdigit
Checkdigit requires the bcmath php 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
andLuhn
for modulo 10 check digits (Luhn is simply a shorthand for Modulo10).Modulo10Gtin
for modulo 10 check digits variant used in GTIN barcodes.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');