-
Notifications
You must be signed in to change notification settings - Fork 43
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
Conversation
There was a problem hiding this 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; | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this 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) { |
There was a problem hiding this comment.
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
butint|array|null
. - I really think the
$options['value']
part is to drop because thegetDefaultOption
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.
This is related to odolbeau#102 that remove the part that I add here.
This is related to odolbeau#102 that remove the part that I add here.
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 😬 . |
Fixes #101
Also using the constructor in tests so that doesn't happen again