-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #188 from cultuurnet/fix-legacy-coding-errors2
Fix legacy coding errors
- Loading branch information
Showing
5 changed files
with
53 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace CultuurNet\UiTPASBeheer\ChecksumValidation; | ||
|
||
class ChecksumValidator | ||
{ | ||
/** | ||
* @param int $number | ||
* @return bool | ||
* @author WN | ||
*/ | ||
public static function validateNumber($number) | ||
{ | ||
return (bool)!self::checksum($number, true); | ||
} | ||
|
||
/** | ||
* @param int|string $number | ||
* @param bool $check Set to true if you are calculating checksum for validation | ||
* @return int | ||
* @author WN | ||
*/ | ||
private static function checksum($number, $check = false) | ||
{ | ||
$data = str_split(strrev($number)); | ||
|
||
$sum = 0; | ||
|
||
foreach ($data as $k => $v) { | ||
|
||
$tmp = $v + $v * (int)(($k % 2) xor !$check); | ||
|
||
if ($tmp > 9) { | ||
$tmp -= 9; | ||
} | ||
|
||
$sum += $tmp; | ||
} | ||
|
||
$sum %= 10; | ||
|
||
return (int)$sum == 0 ? 0 : 10 - $sum; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters