Commit 487a5b29 authored by Jonathan Swaelens's avatar Jonathan Swaelens
Browse files

:sparkles: feat(test): Add orcid test method


Add orcid test method

Signed-off-by: Jonathan Swaelens's avatarJonathan Swaelens <jonathan.swaelens@fusiondirectory.org>
Showing with 16 additions and 0 deletions
+16 -0
...@@ -365,4 +365,20 @@ class tests ...@@ -365,4 +365,20 @@ class tests
return ($ad >= $from && $ad <= $to); return ($ad >= $from && $ad <= $to);
} }
/* \brief Check if the value is a valid orcid id */
public static function is_orcid ($orcid)
{
/* Remove hyphens, remove last digit, convert to array */
$baseDigits = str_split(str_replace('-', '', substr($orcid, 0, -1)));
$sum = 0;
foreach ($baseDigits as $baseDigit) {
$sum = ($sum + (int)$baseDigit) * 2;
}
$remainder = $sum % 11;
$result = (12 - $remainder) % 11;
$orcidCheckSum = (($result == 10) ? "X" : (string)$result);
return ($orcidCheckSum != substr($orcid, -1));
}
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment