Skip to content

[Config] ConfigBuilderGenerator: define template types #54008

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

Open
wants to merge 1 commit into
base: 7.3
Choose a base branch
from

Conversation

thePanz
Copy link
Contributor

@thePanz thePanz commented Feb 20, 2024

Q A
Branch? 7.3
Bug fix? no
New feature? no
Deprecations? no
Issues none
License MIT

This helps phpstan to properly identify the return types, in our case for the $framework->messenger()->transport('async')->dsn(env('MESSENGER_TRANSPORT_DSN'));

Where ->dns() failed with the following Phpstan error:
Call to an undefined method Symfony\Config\Framework\Messenger\TransportConfig|Symfony\Config\Framework\MessengerConfig::dsn()

@carsonbot carsonbot added this to the 7.1 milestone Feb 20, 2024
@thePanz thePanz force-pushed the patch-1 branch 3 times, most recently from 2e524b4 to eca96b0 Compare February 20, 2024 12:36
Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

looks like we're missing a case where we have a union type as "of"

@carsonbot carsonbot changed the title ConfigBuilderGenerator: define template types [Config] ConfigBuilderGenerator: define template types Feb 20, 2024
This helps phpstan to properly identify the return types, in our case for the `$framework->messenger()->transport('async')->dsn(env('MESSENGER_TRANSPORT_DSN'));`

Where  '->dns()` failed with the following Phpstan error:
`Call to an undefined method Symfony\Config\Framework\Messenger\TransportConfig|Symfony\Config\Framework\MessengerConfig::dsn()`
@thePanz
Copy link
Contributor Author

thePanz commented Feb 20, 2024

looks like we're missing a case where we have a union type as "of"

true, all the test cases were only handling mixed.
I would need some help here, maybe @wouterj as the previous editor of those lines can help? 🙏

@thePanz
Copy link
Contributor Author

thePanz commented Feb 20, 2024

Another issue we identified is the messenger routing configuration, which confuses PhpStan.
I have reproduced it here: https://phpstan.org/r/27a18bc2-2e96-499c-b456-f88803542f8f

But could not find a way to solve it, notes:

  • the $value is always an array
  • the value's check for is_array is not needed IMO

@xabbuh xabbuh modified the milestones: 7.1, 7.2 May 15, 2024
@fabpot fabpot modified the milestones: 7.2, 7.3 Nov 20, 2024
@robotomarvin
Copy link

robotomarvin commented Apr 27, 2025

Another issue we identified is the messenger routing configuration, which confuses PhpStan. I have reproduced it here: https://phpstan.org/r/27a18bc2-2e96-499c-b456-f88803542f8f

But could not find a way to solve it, notes:

  • the $value is always an array
  • the value's check for is_array is not needed IMO

@thePanz for some reason PHPStan have two problems here that should be solved on PHPStan side (I think), conditional return on template does not work properly, and native return with static is overwriting conditional return type, this would work for PHPStan
https://phpstan.org/r/25fffe6f-8540-4c33-b49a-423b49b13ce0

I have also reported bug for the dead code / bad native typing to $value here #60282

Edit: this would also work for PHPStan even with conditional return based on generics https://phpstan.org/r/9ecae399-0ee4-4deb-9dc5-a1f3db4017b0

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.

6 participants