8000 [Form] backport type fixes by nicolas-grekas · Pull Request #42013 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Form] backport type fixes #42013

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

Merged
merged 1 commit into from
Jul 17, 2021
Merged

[Form] backport type fixes #42013

merged 1 commit into from
Jul 17, 2021

Conversation

nicolas-grekas
Copy link
Member
Q A
Branch? 5.2
Bug fix? no
New feature? no
Deprecations? no
Tickets -
License MIT
Doc PR -

Backported from #41998

@carsonbot
Copy link

Hey!

I think @VincentLanglet has recently worked with this code. Maybe they can help review this?

Cheers!

Carsonbot

* generating the choice values
* @param callable|Cache\ChoiceFilter|null $filter The callable or static option for
* filtering the choices
* @param callable|string|Cache\ChoiceValue|null $value The callable or static option for
Copy link
Member

Choose a reason for hiding this comment

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

This looks wrong to me. Where do we use arbitrary strings?

Copy link
Member

Choose a reason for hiding this comment

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

strings are for property paths IIRC

Copy link
Member

Choose a reason for hiding this comment

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

If that's the case, we should update the description accordingly IMO.

Copy link
Member Author

Choose a reason for hiding this comment

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

That's because of PropertyAccessDecorator, which also accept PropertyPath btw.
This makes me think that:

  1. PropertyAccessDecorator should maybe accept PropertyPath instead?
  2. CachingFactoryDecorator should accept mixed here, because it shouldn't know anything about what it decorates.

WDYT?

@nicolas-grekas
Copy link
Member Author

* generating the choice values
* @param callable|Cache\ChoiceFilter|null $filter The callable or static option for
* filtering the choices
* @param mixed $value
Copy link
Member

Choose a reason for hiding this comment

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

I don't think that this is really correct as we are forwarding the input and there is no guarantee that the decorated factory handles every input type as well.

Copy link
Member Author
@nicolas-grekas nicolas-grekas Jul 9, 2021

Choose a reason for hiding this comment

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

A decorator cannot provide this guarantee, but it cannot restrict the accepted types either.
The decorated will throw as expected if an incompatible type is provided.
That's the correct behavior IMHO.

* @param mixed $label
* @param mixed $index
* @param mixed $groupBy
* @ 8000 param mixed $attr
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member Author
@nicolas-grekas nicolas-grekas Jul 15, 2021

Choose a reason for hiding this comment

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

In that commit, I widened the accepted types to make tests pass, without thinking more about it.

Now, using my brain a bit more, I realized that we had to add string because that's what PropertyAccessDecorator accepts. But since when is CachingFactoryDecorator coupled in anyway with PropertyAccessDecorator???

A decorator cannot know/restrict the types it accepts here, because it doesn't know what it decorates exactly.

So yes, I'm sure :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense

@Tobion
Copy link
Contributor
Tobion commented Jul 17, 2021

Thank you @nicolas-grekas.

@Tobion Tobion merged commit 2e8eed8 into symfony:5.2 Jul 17, 2021
@nicolas-grekas nicolas-grekas deleted the form-phpdoc52 branch July 23, 2021 16:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
0