odolbeau / phone-number-bundle

Integrates libphonenumber into your Symfony application
MIT License
217 stars 43 forks source link

Usage of the argument $format to specify options is deprecated and will be removed in 4.0. Use "$option" argument instead #113

Closed palanisamy-emis closed 2 years ago

palanisamy-emis commented 2 years ago

Usage of the argument $format to specify options is deprecated and will be removed in 4.0. Use "$option" argument instead

maxhelias commented 2 years ago

what is the issue ?

Nek- commented 2 years ago

Hello,

Thank you for trying to report an issue. But as @maxhelias highlighted, you are not referring any issue related to the phone number bundle.

Please provide actual issue as well as the version you are using (you may just use a too old version and should upgrade).

facundososalopez commented 2 years ago

Hello, I have the same deprecated message:

image

palanisamy-emis commented 2 years ago

Yeah I. too. have the same deprecated message. It came from validator/Constraints/PhoneNumber.php. @Nek- @, @maxhelias

OskarStark commented 2 years ago

Which version of the bundle are you using?

palanisamy-emis commented 2 years ago

v3.6.2 @OskarStark

jderusse commented 2 years ago

You should not pass an array when declaring the constraint.

- new PhoneNumber(['defaultRegion' => 'GB']);
+ new PhoneNumber(defaultRegion: 'GB');

- #[AssertPhoneNumber(['defaultRegion' => 'GB']]
+ #[AssertPhoneNumber(defaultRegion: 'GB')]

- * @AssertPhoneNumber({"defaultRegion": "GB"}]
+ * @AssertPhoneNumber(defaultRegion="GB"]
facundososalopez commented 2 years ago

I'm using the Assert like this everywhere in my code: image

i'll keep checking what is causing the message

I'm using odolbeau/phone-number-bundle v3.6.2

okorneliuk commented 2 years ago

The origin of this issue is here: https://github.com/doctrine/annotations/blob/1.13.x/docs/en/custom.rst#optional-constructors-with-named-parameters

We should add @NamedArgumentConstructor annotation, but should we handle the situation, when the class NamedArgumentConstructor is missing?

Nek- commented 2 years ago

Thank you @okorneliuk for pointing that out!

So here it is. If you specifies the (optional) format argument, you will have a deprecation issue. The way to avoid any problem is to follow directives in the documentation:

With annotations:

use Misd\PhoneNumberBundle\Validator\Constraints\PhoneNumber as AssertPhoneNumber;

// https://github.com/odolbeau/phone-number-bundle/blob/v3.4.2/README.md#validating-phone-numbers
/** @AssertPhoneNumber(defaultRegion="GB") */
private $phoneNumber;

With attributes:

use Misd\PhoneNumberBundle\Validator\Constraints\PhoneNumber as AssertPhoneNumber;

// https://github.com/odolbeau/phone-number-bundle#validating-phone-numbers
 #[AssertPhoneNumber(defaultRegion: 'GB')]
private $phoneNumber;

In plain PHP:

new PhoneNumber(defaultRegion: 'GB');

That said, the annotation version have a little issue, connected to the annotation declaration missing option. This is why I suggest this PR: #119

Nek- commented 2 years ago

The fix on the annotation has been merged. This issue can be closed :) .

garak commented 1 year ago

I'm sorry to comment on a closed issue. I see that this was closed last July, and two new versions (3.8.0 in October and 3.9.0 in December) were released after that. Nonetheless, the issue is still present.

garak commented 1 year ago

Just to be more clear, the following is the validation configuration I'm using:

<?xml version="1.0" encoding="UTF-8" ?>
<constraint-mapping xmlns="http://symfony.com/schema/dic/constraint-mapping"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://symfony.com/schema/dic/constraint-mapping https://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd"
>
    <class name="MyNamespace\MyClass">
        <property name="phone">
            <constraint name="Misd\PhoneNumberBundle\Validator\Constraints\PhoneNumber">
                <option name="defaultRegion">IT</option>
            </constraint>
        </property>
    </class>
</constraint-mapping>

I checked the README and, even if in a different format, this is the suggested way to use a default region. Unfortunately, this is still causing the deprecation warning to be present (probably the solution proposed in the linked PR was not enough)

Nek- commented 1 year ago

Thank you for highlighting this @garak . I opened https://github.com/odolbeau/phone-number-bundle/pull/139 to fix it. Do you think it will fix your issue?

garak commented 1 year ago

Thank you for highlighting this @garak . I opened #139 to fix it. Do you think it will fix your issue?

Yes, it does. Thank you for the prompt response.