Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
10 / 10 |
CheckDigit | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
4 | |
100.00% |
10 / 10 |
modulus10wait3 | |
100.00% |
1 / 1 |
4 | |
100.00% |
10 / 10 |
<?php | |
namespace Puyo\Calc; | |
/** | |
* CheckDigit 算出 | |
*/ | |
class CheckDigit | |
{ | |
/** | |
* @param string|int $num | |
* @return string check digit | |
*/ | |
public static function modulus10wait3($num) { | |
$chars = array_reverse(str_split($num)); | |
$numOfChars = count($chars); | |
$total = 0; | |
for($i=0; $i<$numOfChars; $i++) { | |
$total += ( ($i+1) % 2) == 0 ? intval($chars[$i]) : intval($chars[$i])*3; | |
} | |
$totalLastChar = substr($total, strlen($total) - 1, 1); | |
$intCd = 10 - intval($totalLastChar); | |
if($intCd < 10) { | |
return strval($intCd); | |
} else { | |
return '0'; | |
} | |
} | |
} |