Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix constructor breaking with format as input #102

Merged
merged 3 commits into from
Feb 24, 2022

Conversation

KDederichs
Copy link

Fixes #101
Also using the constructor in tests so that doesn't happen again

Copy link
Collaborator

@Nek- Nek- left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello, thank you very much for your contribution.

This PR seems to be an important fix to work with attributes.

$options = array_merge($format, $options);
} elseif (null !== $format) {
$options['value'] = $format;
}
Copy link
Collaborator

@Nek- Nek- Feb 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks indeed somehow wrong. Maybe it's done on purpose? cc @jderusse

Asking because it's a bc break if it may be useful in a case.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It kinda looks to me to be some BC code to some REALLY old SF versions (2.x maybe).
I've gone through the code trying to find any use for it but could not (tests passing without it also suggests it wasn't used anywhere).
But yeah some extra confirmation might be good

Copy link
Collaborator

@Nek- Nek- left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't push on your PR (you need to enable this in the options of the PR) so I let you fix this or I will create a new PR with your work.

Thanks anyway for highlighting that, probably a lot of people hit this issue without reporting it!

@@ -54,12 +54,6 @@ class PhoneNumber extends Constraint
*/
public function __construct($format = null, $type = null, string $defaultRegion = null, string $regionPath = null, string $message = null, array $groups = null, $payload = null, array $options = [])
{
if (\is_array($format)) {
$options = array_merge($format, $options);
} elseif (null !== $format) {
Copy link
Collaborator

@Nek- Nek- Feb 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • The first if seems to be (unfortunately) an important BC break. We are going to keep it besides it's not great.
  • The $format var is therefore not string|array|null but int|array|null.
  • I really think the $options['value'] part is to drop because the getDefaultOption is not defined.
  • We should trigger a deprecation if an options array is passed instead of the format.
  • Finally we should add some doc to the docbloc to make the usage more clear and maybe rename the format $formatOrOptions.

edit: my bad, I was able to do it.

Nek- added a commit to KDederichs/phone-number-bundle that referenced this pull request Feb 23, 2022
This is related to odolbeau#102 that remove the part that I add here.
@Nek-
Copy link
Collaborator

Nek- commented Feb 24, 2022

I squashed your work. Added the part I was talking about in my last comment.

PHPStan failures are unrelated. (seems to be an issue from the image we use)

Everything is ready to be merged, except this failure 😬 .

@Nek- Nek- merged commit d6e588d into odolbeau:master Feb 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PhoneNumber constraint breaks when you ser a format
2 participants