Replace PhonenumberConstraint with MisdPhoneNumberConstraint across entities, deprecate outdated validation logic, and remove unused methods for improved phone number validation.

This commit is contained in:
2025-09-17 13:39:09 +02:00
parent ff2c567d05
commit 4a73aaae94
11 changed files with 30 additions and 20 deletions

View File

@@ -86,14 +86,14 @@ class Immersion implements \Stringable
* @Assert\NotBlank() * @Assert\NotBlank()
*/ */
#[ORM\Column(name: 'tuteurPhoneNumber', type: 'phone_number', nullable: true)] #[ORM\Column(name: 'tuteurPhoneNumber', type: 'phone_number', nullable: true)]
#[PhonenumberConstraint(type: 'any')] #[\Misd\PhoneNumberBundle\Validator\Constraints\PhoneNumber]
private ?PhoneNumber $tuteurPhoneNumber = null; private ?PhoneNumber $tuteurPhoneNumber = null;
#[ORM\Column(name: 'structureAccName', type: \Doctrine\DBAL\Types\Types::TEXT, nullable: true)] #[ORM\Column(name: 'structureAccName', type: \Doctrine\DBAL\Types\Types::TEXT, nullable: true)]
private ?string $structureAccName = null; private ?string $structureAccName = null;
#[ORM\Column(name: 'structureAccPhonenumber', type: 'phone_number', nullable: true)] #[ORM\Column(name: 'structureAccPhonenumber', type: 'phone_number', nullable: true)]
#[PhonenumberConstraint(type: 'any')] #[\Misd\PhoneNumberBundle\Validator\Constraints\PhoneNumber]
private ?PhoneNumber $structureAccPhonenumber = null; private ?PhoneNumber $structureAccPhonenumber = null;
#[ORM\Column(name: 'structureAccEmail', type: \Doctrine\DBAL\Types\Types::TEXT, nullable: true)] #[ORM\Column(name: 'structureAccEmail', type: \Doctrine\DBAL\Types\Types::TEXT, nullable: true)]

View File

@@ -14,9 +14,9 @@ namespace Chill\MainBundle\Entity;
use Chill\MainBundle\Doctrine\Model\TrackCreationInterface; use Chill\MainBundle\Doctrine\Model\TrackCreationInterface;
use Chill\MainBundle\Doctrine\Model\TrackUpdateInterface; use Chill\MainBundle\Doctrine\Model\TrackUpdateInterface;
use Chill\MainBundle\Repository\LocationRepository; use Chill\MainBundle\Repository\LocationRepository;
use Chill\MainBundle\Validation\Constraint\PhonenumberConstraint;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use libphonenumber\PhoneNumber; use libphonenumber\PhoneNumber;
use Misd\PhoneNumberBundle\Validator\Constraints\PhoneNumber as MisdPhoneNumberConstraint;
use Symfony\Component\Serializer\Annotation as Serializer; use Symfony\Component\Serializer\Annotation as Serializer;
use Symfony\Component\Serializer\Annotation\DiscriminatorMap; use Symfony\Component\Serializer\Annotation\DiscriminatorMap;
@@ -67,12 +67,12 @@ class Location implements TrackCreationInterface, TrackUpdateInterface
#[Serializer\Groups(['read', 'write', 'docgen:read'])] #[Serializer\Groups(['read', 'write', 'docgen:read'])]
#[ORM\Column(type: 'phone_number', nullable: true)] #[ORM\Column(type: 'phone_number', nullable: true)]
#[PhonenumberConstraint(type: 'any')] #[MisdPhoneNumberConstraint(type: [MisdPhoneNumberConstraint::ANY])]
private ?PhoneNumber $phonenumber1 = null; private ?PhoneNumber $phonenumber1 = null;
#[Serializer\Groups(['read', 'write', 'docgen:read'])] #[Serializer\Groups(['read', 'write', 'docgen:read'])]
#[ORM\Column(type: 'phone_number', nullable: true)] #[ORM\Column(type: 'phone_number', nullable: true)]
#[PhonenumberConstraint(type: 'any')] #[MisdPhoneNumberConstraint(type: [MisdPhoneNumberConstraint::ANY])]
private ?PhoneNumber $phonenumber2 = null; private ?PhoneNumber $phonenumber2 = null;
#[Serializer\Groups(['read'])] #[Serializer\Groups(['read'])]

View File

@@ -23,7 +23,6 @@ use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface; use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Serializer\Annotation as Serializer; use Symfony\Component\Serializer\Annotation as Serializer;
use Symfony\Component\Validator\Context\ExecutionContextInterface; use Symfony\Component\Validator\Context\ExecutionContextInterface;
use Chill\MainBundle\Validation\Constraint\PhonenumberConstraint;
/** /**
* User. * User.
@@ -116,7 +115,7 @@ class User implements UserInterface, \Stringable, PasswordAuthenticatedUserInter
* The user's mobile phone number. * The user's mobile phone number.
*/ */
#[ORM\Column(type: 'phone_number', nullable: true)] #[ORM\Column(type: 'phone_number', nullable: true)]
#[PhonenumberConstraint] #[\Misd\PhoneNumberBundle\Validator\Constraints\PhoneNumber]
private ?PhoneNumber $phonenumber = null; private ?PhoneNumber $phonenumber = null;
/** /**

View File

@@ -31,6 +31,8 @@ interface PhoneNumberHelperInterface
/** /**
* Return true if the validation is configured and available. * Return true if the validation is configured and available.
*
* @deprecated this is an internal behaviour of the helper and should not be taken into account outside of the implementation
*/ */
public function isPhonenumberValidationConfigured(): bool; public function isPhonenumberValidationConfigured(): bool;

View File

@@ -122,7 +122,7 @@ final class PhonenumberHelper implements PhoneNumberHelperInterface
*/ */
public function isValidPhonenumberAny($phonenumber): bool public function isValidPhonenumberAny($phonenumber): bool
{ {
if (false === $this->isPhonenumberValidationConfigured()) { if (false === $this->isConfigured) {
return true; return true;
} }
$validation = $this->performTwilioLookup($phonenumber); $validation = $this->performTwilioLookup($phonenumber);
@@ -142,7 +142,7 @@ final class PhonenumberHelper implements PhoneNumberHelperInterface
*/ */
public function isValidPhonenumberLandOrVoip($phonenumber): bool public function isValidPhonenumberLandOrVoip($phonenumber): bool
{ {
if (false === $this->isPhonenumberValidationConfigured()) { if (false === $this->isConfigured) {
return true; return true;
} }
@@ -163,7 +163,7 @@ final class PhonenumberHelper implements PhoneNumberHelperInterface
*/ */
public function isValidPhonenumberMobile($phonenumber): bool public function isValidPhonenumberMobile($phonenumber): bool
{ {
if (false === $this->isPhonenumberValidationConfigured()) { if (false === $this->isConfigured) {
return true; return true;
} }
@@ -178,7 +178,7 @@ final class PhonenumberHelper implements PhoneNumberHelperInterface
private function performTwilioLookup($phonenumber) private function performTwilioLookup($phonenumber)
{ {
if (false === $this->isPhonenumberValidationConfigured()) { if (false === $this->isConfigured) {
return null; return null;
} }

View File

@@ -46,7 +46,10 @@ class PhonenumberNormalizer implements ContextAwareNormalizerInterface, Denormal
try { try {
return $this->phoneNumberUtil->parse($data, $this->defaultCarrierCode); return $this->phoneNumberUtil->parse($data, $this->defaultCarrierCode);
} catch (NumberParseException $e) { } catch (NumberParseException $e) {
throw new UnexpectedValueException($e->getMessage(), $e->getCode(), $e); $phonenumber = new PhoneNumber();
$phonenumber->setRawInput($data);
return $phonenumber;
} }
} }

View File

@@ -13,6 +13,9 @@ namespace Chill\MainBundle\Validation\Constraint;
use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\Constraint;
/**
* @deprecated use odolbeau/phonenumber validator instead
*/
#[\Attribute(\Attribute::TARGET_PROPERTY | \Attribute::TARGET_METHOD)] #[\Attribute(\Attribute::TARGET_PROPERTY | \Attribute::TARGET_METHOD)]
class PhonenumberConstraint extends Constraint class PhonenumberConstraint extends Constraint
{ {

View File

@@ -16,6 +16,9 @@ use Psr\Log\LoggerInterface;
use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator; use Symfony\Component\Validator\ConstraintValidator;
/**
* @deprecated use https://github.com/odolbeau/phone-number-bundle/blob/master/src/Validator/Constraints/PhoneNumberValidator.php instead
*/
final class ValidPhonenumber extends ConstraintValidator final class ValidPhonenumber extends ConstraintValidator
{ {
public function __construct(private readonly LoggerInterface $logger, private readonly PhoneNumberHelperInterface $phonenumberHelper) {} public function __construct(private readonly LoggerInterface $logger, private readonly PhoneNumberHelperInterface $phonenumberHelper) {}

View File

@@ -27,7 +27,6 @@ use Chill\MainBundle\Entity\Language;
use Chill\MainBundle\Entity\User; use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Entity\Workflow\EntityWorkflowSignatureStateEnum; use Chill\MainBundle\Entity\Workflow\EntityWorkflowSignatureStateEnum;
use Chill\MainBundle\Entity\Workflow\EntityWorkflowStepSignature; use Chill\MainBundle\Entity\Workflow\EntityWorkflowStepSignature;
use Chill\MainBundle\Validation\Constraint\PhonenumberConstraint;
use Chill\PersonBundle\Entity\Household\Household; use Chill\PersonBundle\Entity\Household\Household;
use Chill\PersonBundle\Entity\Household\HouseholdMember; use Chill\PersonBundle\Entity\Household\HouseholdMember;
use Chill\PersonBundle\Entity\Household\PersonHouseholdAddress; use Chill\PersonBundle\Entity\Household\PersonHouseholdAddress;
@@ -47,6 +46,7 @@ use Doctrine\Common\Collections\ReadableCollection;
use Doctrine\Common\Collections\Selectable; use Doctrine\Common\Collections\Selectable;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use libphonenumber\PhoneNumber; use libphonenumber\PhoneNumber;
use Misd\PhoneNumberBundle\Validator\Constraints\PhoneNumber as MisdPhoneNumberConstraint;
use Symfony\Component\Serializer\Annotation\DiscriminatorMap; use Symfony\Component\Serializer\Annotation\DiscriminatorMap;
use Symfony\Component\Validator\Constraints as Assert; use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Context\ExecutionContextInterface; use Symfony\Component\Validator\Context\ExecutionContextInterface;
@@ -319,7 +319,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
* The person's mobile phone number. * The person's mobile phone number.
*/ */
#[ORM\Column(type: 'phone_number', nullable: true)] #[ORM\Column(type: 'phone_number', nullable: true)]
#[PhonenumberConstraint(type: 'mobile')] #[MisdPhoneNumberConstraint(type: [MisdPhoneNumberConstraint::MOBILE])]
private ?PhoneNumber $mobilenumber = null; private ?PhoneNumber $mobilenumber = null;
/** /**
@@ -359,7 +359,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
* The person's phonenumber. * The person's phonenumber.
*/ */
#[ORM\Column(type: 'phone_number', nullable: true)] #[ORM\Column(type: 'phone_number', nullable: true)]
#[PhonenumberConstraint(type: 'landline')] #[MisdPhoneNumberConstraint(type: [MisdPhoneNumberConstraint::FIXED_LINE, MisdPhoneNumberConstraint::VOIP, MisdPhoneNumberConstraint::PERSONAL_NUMBER])]
private ?PhoneNumber $phonenumber = null; private ?PhoneNumber $phonenumber = null;
/** /**

View File

@@ -6,7 +6,6 @@
id="lastname" id="lastname"
v-model="lastName" v-model="lastName"
:placeholder="trans(PERSON_MESSAGES_PERSON_LASTNAME)" :placeholder="trans(PERSON_MESSAGES_PERSON_LASTNAME)"
@change="checkErrors"
/> />
<label for="lastname">{{ trans(PERSON_MESSAGES_PERSON_LASTNAME) }}</label> <label for="lastname">{{ trans(PERSON_MESSAGES_PERSON_LASTNAME) }}</label>
</div> </div>
@@ -29,7 +28,6 @@
id="firstname" id="firstname"
v-model="firstName" v-model="firstName"
:placeholder="trans(PERSON_MESSAGES_PERSON_FIRSTNAME)" :placeholder="trans(PERSON_MESSAGES_PERSON_FIRSTNAME)"
@change="checkErrors"
/> />
<label for="firstname">{{ <label for="firstname">{{
trans(PERSON_MESSAGES_PERSON_FIRSTNAME) trans(PERSON_MESSAGES_PERSON_FIRSTNAME)
@@ -401,6 +399,7 @@ const queryItems = computed(() => {
.filter((word) => !lastNameWords.includes(word.toLowerCase())); .filter((word) => !lastNameWords.includes(word.toLowerCase()));
}); });
/*
function checkErrors() { function checkErrors() {
errors.value = []; errors.value = [];
if (person.lastName === "") { if (person.lastName === "") {
@@ -417,6 +416,8 @@ function checkErrors() {
} }
} }
*/
async function loadData() { async function loadData() {
if (props.id !== undefined && props.id !== null) { if (props.id !== undefined && props.id !== null) {
const person = await getPerson(props.id); const person = await getPerson(props.id);

View File

@@ -17,7 +17,6 @@ use Chill\MainBundle\Entity\Address;
use Chill\MainBundle\Entity\Center; use Chill\MainBundle\Entity\Center;
use Chill\MainBundle\Entity\Civility; use Chill\MainBundle\Entity\Civility;
use Chill\MainBundle\Entity\User; use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Validation\Constraint\PhonenumberConstraint;
use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection; use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\ReadableCollection; use Doctrine\Common\Collections\ReadableCollection;
@@ -206,12 +205,12 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface, \Strin
#[Groups(['read', 'write', 'docgen:read', 'docgen:read:3party:parent'])] #[Groups(['read', 'write', 'docgen:read', 'docgen:read:3party:parent'])]
#[ORM\Column(name: 'telephone', type: 'phone_number', nullable: true)] #[ORM\Column(name: 'telephone', type: 'phone_number', nullable: true)]
#[PhonenumberConstraint(type: 'any')] #[\Misd\PhoneNumberBundle\Validator\Constraints\PhoneNumber]
private ?PhoneNumber $telephone = null; private ?PhoneNumber $telephone = null;
#[Groups(['read', 'write', 'docgen:read', 'docgen:read:3party:parent'])] #[Groups(['read', 'write', 'docgen:read', 'docgen:read:3party:parent'])]
#[ORM\Column(name: 'telephone2', type: 'phone_number', nullable: true)] #[ORM\Column(name: 'telephone2', type: 'phone_number', nullable: true)]
#[PhonenumberConstraint(type: 'any')] #[\Misd\PhoneNumberBundle\Validator\Constraints\PhoneNumber]
private ?PhoneNumber $telephone2 = null; private ?PhoneNumber $telephone2 = null;
#[ORM\Column(name: 'types', type: \Doctrine\DBAL\Types\Types::JSON, nullable: true)] #[ORM\Column(name: 'types', type: \Doctrine\DBAL\Types\Types::JSON, nullable: true)]