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 1155d0675b
commit bd0fb0024f
11 changed files with 30 additions and 20 deletions

View File

@@ -14,9 +14,9 @@ namespace Chill\MainBundle\Entity;
use Chill\MainBundle\Doctrine\Model\TrackCreationInterface;
use Chill\MainBundle\Doctrine\Model\TrackUpdateInterface;
use Chill\MainBundle\Repository\LocationRepository;
use Chill\MainBundle\Validation\Constraint\PhonenumberConstraint;
use Doctrine\ORM\Mapping as ORM;
use libphonenumber\PhoneNumber;
use Misd\PhoneNumberBundle\Validator\Constraints\PhoneNumber as MisdPhoneNumberConstraint;
use Symfony\Component\Serializer\Annotation as Serializer;
use Symfony\Component\Serializer\Annotation\DiscriminatorMap;
@@ -67,12 +67,12 @@ class Location implements TrackCreationInterface, TrackUpdateInterface
#[Serializer\Groups(['read', 'write', 'docgen:read'])]
#[ORM\Column(type: 'phone_number', nullable: true)]
#[PhonenumberConstraint(type: 'any')]
#[MisdPhoneNumberConstraint(type: [MisdPhoneNumberConstraint::ANY])]
private ?PhoneNumber $phonenumber1 = null;
#[Serializer\Groups(['read', 'write', 'docgen:read'])]
#[ORM\Column(type: 'phone_number', nullable: true)]
#[PhonenumberConstraint(type: 'any')]
#[MisdPhoneNumberConstraint(type: [MisdPhoneNumberConstraint::ANY])]
private ?PhoneNumber $phonenumber2 = null;
#[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\Serializer\Annotation as Serializer;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
use Chill\MainBundle\Validation\Constraint\PhonenumberConstraint;
/**
* User.
@@ -116,7 +115,7 @@ class User implements UserInterface, \Stringable, PasswordAuthenticatedUserInter
* The user's mobile phone number.
*/
#[ORM\Column(type: 'phone_number', nullable: true)]
#[PhonenumberConstraint]
#[\Misd\PhoneNumberBundle\Validator\Constraints\PhoneNumber]
private ?PhoneNumber $phonenumber = null;
/**

View File

@@ -31,6 +31,8 @@ interface PhoneNumberHelperInterface
/**
* 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;

View File

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

View File

@@ -46,7 +46,10 @@ class PhonenumberNormalizer implements ContextAwareNormalizerInterface, Denormal
try {
return $this->phoneNumberUtil->parse($data, $this->defaultCarrierCode);
} 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;
/**
* @deprecated use odolbeau/phonenumber validator instead
*/
#[\Attribute(\Attribute::TARGET_PROPERTY | \Attribute::TARGET_METHOD)]
class PhonenumberConstraint extends Constraint
{

View File

@@ -16,6 +16,9 @@ use Psr\Log\LoggerInterface;
use Symfony\Component\Validator\Constraint;
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
{
public function __construct(private readonly LoggerInterface $logger, private readonly PhoneNumberHelperInterface $phonenumberHelper) {}