parent
04cbe54dd1
commit
220c0ece82
18 changed files with 95 additions and 22 deletions
|
|
@ -4,6 +4,29 @@ declare(strict_types=1);
|
|||
|
||||
final class Ids
|
||||
{
|
||||
public static function validRna(string $value): bool
|
||||
{
|
||||
$value = strtoupper(preg_replace('/\s+/', '', trim($value)) ?? '');
|
||||
return $value === '' || preg_match('/^W[0-9]{9}$/', $value) === 1;
|
||||
}
|
||||
|
||||
public static function validSiret(string $value): bool
|
||||
{
|
||||
$digits = preg_replace('/\D+/', '', trim($value)) ?? '';
|
||||
if ($digits === '') {
|
||||
return true;
|
||||
}
|
||||
if (strlen($digits) !== 14) {
|
||||
return false;
|
||||
}
|
||||
$sum = 0;
|
||||
foreach (str_split($digits) as $index => $digit) {
|
||||
$number = (int) $digit * ($index % 2 === 0 ? 2 : 1);
|
||||
$sum += $number > 9 ? $number - 9 : $number;
|
||||
}
|
||||
return $sum % 10 === 0;
|
||||
}
|
||||
|
||||
public static function slugifyUpper(string $s): string
|
||||
{
|
||||
$s = trim($s);
|
||||
|
|
|
|||
Loading…
Reference in a new issue