2017 © Pedro Peláez
 

library hkid-check-digit

HKID digit check

image

ilexn/hkid-check-digit

HKID digit check

  • Thursday, February 8, 2018
  • by iLexN
  • Repository
  • 0 Watchers
  • 0 Stars
  • 37 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 7 Versions
  • 12 % Grown

The README.md

Validation of HKID

Used to validation the format and check digit calculation for HKID., (*1)

 __    __   __  ___  __   _______       ______  __    __   _______   ______  __  ___
|  |  |  | |  |/  / |  | |       \     /      ||  |  |  | |   ____| /      ||  |/  /
|  |__|  | |  '  /  |  | |  .--.  |   |  ,----'|  |__|  | |  |__   |  ,----'|  '  / 
|   __   | |    <   |  | |  |  |  |   |  |     |   __   | |   __|  |  |     |    <  
|  |  |  | |  .  \  |  | |  '--'  |   |  `----.|  |  |  | |  |____ |  `----.|  .  \ 
|__|  |__| |__|\__\ |__| |_______/     \______||__|  |__| |_______| \______||__|\__\

Latest Stable Version Total Downloads, (*2)

GitHub Action Coverage Status Mutation testing badge, (*3)

Tag PHP
1.x
2.x php>=7.1
3.x php>=7.4
4.x php>=8.0
5.x php>=8.1

Installation

composer require ilexn/hkid-check-digit

Upgrade from 4.x to 5.x

The \Ilex\Validation\HkidValidation\Reason\ReasonInterface changed to Enum \Ilex\Validation\HkidValidation\Enum\Reason, (*4)

//4.x
switch ($hkid->getReason()){
    case \Ilex\Validation\HkidValidation\Reason\ReasonInterface::OK:
        echo('correct');
        echo($hkid->format());
        break;
    case \Ilex\Validation\HkidValidation\Reason\ReasonInterface::PATTEN_ERROR:
        echo('Patten not match');
        break;
    case \Ilex\Validation\HkidValidation\Reason\ReasonInterface::DIGIT_ERROR:
        echo('Digit not match');
        break;
}

//5.x
switch ($hkid->getReason()){
    case \Ilex\Validation\HkidValidation\Enum\Reason::Ok:
        echo('correct');
        echo($hkid->format());
        break;
    case \Ilex\Validation\HkidValidation\Enum\Reason::PattenError:
        echo('Patten not match');
        break;
    case \Ilex\Validation\HkidValidation\Enum\Reason::DigitError:
        echo('Digit not match');
        break;
}

Upgrade from 2.x to 3.x

All the checking now return \Ilex\Validation\HkidValidation\HkId object, not bool, (*5)

<?php
use Ilex\Validation\HkidValidation\Helper;

require_once 'vendor/autoload.php';
$a = Helper::checkByString($s);
//2.x: $a is bool

//>=3.x
$a->isValid(); //bool
$a->isPattenError(); //bool
$a->isDigitError(); //bool
echo($a->format()); // print the formated HKID.
echo($a->getReason());

//also can get back each parts
echo($a->getPart1());
echo($a->getPart2());
echo($a->getPart3());

Usage example

Quick helper - check by each part

<?php
use Ilex\Validation\HkidValidation\Helper;

require_once 'vendor/autoload.php';

//CA182361(1)
$p1 = 'CA';
$p2 = '182361';
$p3 = '1';

$a = Helper::checkByParts($p1, $p2, $p3);

if ($a->isValid()) {
    echo ('correct');
    echo $a->format(); //CA182361(1)
    echo (string) $a; //CA182361(1)
} else {
    echo ('wrong');
}

Quick helper - check by string

<?php
use Ilex\Validation\HkidValidation\Enum\Reason;use Ilex\Validation\HkidValidation\Helper;

require_once 'vendor/autoload.php';

$s = 'CA182361(1)';

$hkid = Helper::checkByString($s);

switch ($hkid->getReason()){
    case \Ilex\Validation\HkidValidation\Enum\Reason::Ok:
        echo('correct');
        echo($hkid->format());
        break;
    case \Ilex\Validation\HkidValidation\Enum\Reason::PattenError:
        echo('Patten not match');
        break;
    case \Ilex\Validation\HkidValidation\Enum\Reason::DigitError:
        echo('Digit not match');
        break;

Normal

<?php
use Ilex\Validation\HkidValidation\HkidDigitCheck;

require_once 'vendor/autoload.php';

$p1 = 'CA';
$p2 = '182361';
$p3 = '1';
$s = 'CA182361(1)';

$c = new HkidDigitCheck();
$hkid = $c->checkParts($p1,$p2,$p3);
if ($hkid->isValid()) {
    echo ('correct');
    echo $hkid->format();
} else {
    echo ('wrong');
    if ($hkid->isPattenError()) {
        echo('Patten not match');
    }
    if ($hkid->isDigitError()) {
        echo('Digit not match');
    }
}

$hkid = $c->checkString($s);
if ($hkid->isValid()) {
    echo ('correct');
    echo $hkid->format();
} else {
    echo ('wrong');
}

The Versions

08/02 2018

dev-master

9999999-dev

HKID digit check

  Sources   Download

MIT

The Requires

  • php >=7.1

 

The Development Requires

by Avatar iLexN

28/01 2018
26/01 2018

dev-add-license-1

dev-add-license-1

HKID digit check

  Sources   Download

MIT

The Requires

  • php >=7.1

 

The Development Requires

by Avatar iLexN

04/01 2016

1.0.6

1.0.6.0

HKID digit check

  Sources   Download

The Requires

  • php >=5.5

 

The Development Requires

by Avatar iLexN

29/12 2015

1.0.5

1.0.5.0

idorm db file cache

  Sources   Download

The Development Requires

by Avatar iLexN

28/12 2015

1.0.4

1.0.4.0

idorm db file cache

  Sources   Download

The Development Requires

by Avatar iLexN

15/12 2015

1.0

1.0.0.0

idorm db file cache

  Sources   Download

The Development Requires

by Avatar iLexN