-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFrenchSirenValidator.php
More file actions
executable file
·37 lines (29 loc) · 1.03 KB
/
FrenchSirenValidator.php
File metadata and controls
executable file
·37 lines (29 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
declare(strict_types=1);
namespace AssoConnect\ValidatorBundle\Validator\Constraints;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\Constraints\LuhnValidator;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
class FrenchSirenValidator extends LuhnValidator
{
/**
* @inheritDoc
*/
public function validate(mixed $value, Constraint $constraint): void
{
if (!$constraint instanceof FrenchSiren) {
throw new UnexpectedTypeException($constraint, FrenchSiren::class);
}
if (null === $value || '' === $value) {
return;
}
if (!is_string($value) || preg_match('/(^\d{9}$)/', $value) !== 1) {
$this->context->buildViolation($constraint->message)
->setParameter('{{ value }}', $this->formatValue($value))
->setCode(FrenchSiren::INVALID_FORMAT_ERROR)
->addViolation();
return;
}
parent::validate($value, $constraint);
}
}