fix Form getValues() invalid type#175
Merged
ondrejmirtes merged 1 commit intophpstan:2.0.xfrom Sep 17, 2025
Merged
Conversation
Member
|
Please add a type inference test about this. Here's an example https://github.com/phpstan/phpstan-nette/blob/2.0.x/tests/Type/Nette/ComponentModelArrayAccessDynamicReturnTypeExtensionTest.php and docs https://phpstan.org/developing-extensions/testing#type-inference. |
8d7bb37 to
7ebc51e
Compare
Contributor
Author
|
@ondrejmirtes Hi, thank you for your quick response. I added the test as required. I also quickly tested if getValues(true), getValues(false) still work and they both throw an exception at runtime, so I removed it from the original code. |
Member
|
Thank you for cleaning up that test! It was really old and now we know better than to mock the whole universe 😊 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes an issue where if you want to map values into a DTO, you need to manually assert the type with assert instanceof.
This PR allows you to do
$values = $form->getValues(MyFormDto::class)and the $values type will be properly typed.