-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Improving extracting type from constructor #10969
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
Improving extracting type from constructor #10969
Conversation
@LS05 thanks for your contribution! However, it seems that this is more complicated than it looks. First, this option is configurable. Maybe we should mention that? And if possible, know why this is configurable (maybe it' too slow?) Second, the |
@javiereguiluz Oh, my bad! Did it early this morning :) |
I think that is configurable because of this recursive call Can this take some time for long subclass relationships? |
Besides me being blind about a private method 😄 I'm running a script on the CLI to understand how the Here the example script:
And I get the following output:
Am I using the
It gives me my desired output:
|
@javiereguiluz @LS05 - hi guys, just saw this on slack and thought i'd take a look - I think this might be a symfony bug - in property-info\Extractor\ReflectionExtractor.php, there is a line that reads: $context['enable_constructor_extraction'] ?? $this->enableConstructorExtraction && I think this might have been meant to read: ($context['enable_constructor_extraction'] ?? $this->enableConstructorExtraction) && |
If passing context to getTypes, it checks value of $context['enable_constructor_extraction'] for true/false or the constructor value of enableConstructorExtraction and should then populate fromConstructor if necessary. The missing brackets around the first part of this check mean that fromConstructor is only applied if context is not set. This fixes the issuse described at [symfony/symfony-docs#10969](symfony/symfony-docs#10969)
If passing context to getTypes, it checks value of $context['enable_constructor_extraction'] for true/false or the constructor value of enableConstructorExtraction and should then populate fromConstructor if necessary. The missing brackets around the first part of this check mean that fromConstructor is only applied if context is not set. This fixes the issuse described at [symfony/symfony-docs#10969](symfony/symfony-docs#10969)
If passing context to getTypes, it checks value of $context['enable_constructor_extraction'] for true/false or the constructor value of enableConstructorExtraction and should then populate fromConstructor if necessary. The missing brackets around the first part of this check mean that fromConstructor is only applied if context is not set. This fixes the issuse described at [symfony/symfony-docs#10969](symfony/symfony-docs#10969)
@mantis Thanks! I had that error too, but I thought I was calling the class the wrong way :) @javiereguiluz Could it be that is configurable because in the constructor is possible to set |
If passing context to getTypes, it checks value of $context['enable_constructor_extraction'] for true/false or the constructor value of enableConstructorExtraction and should then populate fromConstructor if necessary. The missing brackets around the first part of this check mean that fromConstructor is only applied if context is not set. This fixes the issuse described at [symfony/symfony-docs#10969](symfony/symfony-docs#10969)
… passing context to getTypes (mantis, OskarStark) This PR was merged into the 4.2 branch. Discussion ---------- [PropertyInfo] Fix undefined variable fromConstructor when passing context to getTypes | Q | A | ------------- | --- | Branch? | 4.1, 4.2, master | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | symfony/symfony-docs#10969 | License | MIT | Doc PR | If passing context to getTypes, it checks value of $context['enable_constructor_extraction'] for true/false or the constructor value of enableConstructorExtraction and should then populate fromConstructor if necessary. The missing brackets around the first part of this check mean that fromConstructor is only applied if context is not set. This fixes the issue described at [symfony/symfony-docs#10969](symfony/symfony-docs#10969) Commits ------- 8e401af Allow 3rd argument to be null 04dc692 Remove whitespace (tab on blank line) a0aa15a Update src/Symfony/Component/PropertyInfo/Tests/Extractor/ReflectionExtractorTest.php c2986d5 Update src/Symfony/Component/PropertyInfo/Tests/Extractor/ReflectionExtractorTest.php 42995c8 Update src/Symfony/Component/PropertyInfo/Tests/Extractor/ReflectionExtractorTest.php 2d88298 Update src/Symfony/Component/PropertyInfo/Tests/Extractor/ReflectionExtractorTest.php e43a3bc Update ReflectionExtractorTest.php 2c91c75 Update ReflectionExtractorTest.php 5acc85c Update ReflectionExtractorTest.php d0a2dc0 Update ReflectionExtractorTest.php be8d14a Fix undefined variable fromConstructor when passing context to getTypes
… passing context to getTypes (mantis) This PR was merged into the 4.2 branch. Discussion ---------- [PropertyInfo] Fix undefined variable fromConstructor when passing context to getTypes | Q | A | ------------- | --- | Branch? | 4.1, 4.2, master | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | symfony/symfony-docs#10969 | License | MIT | Doc PR | If passing context to getTypes, it checks value of $context['enable_constructor_extraction'] for true/false or the constructor value of enableConstructorExtraction and should then populate fromConstructor if necessary. The missing brackets around the first part of this check mean that fromConstructor is only applied if context is not set. This fixes the issue described at [symfony/symfony-docs#10969](symfony/symfony-docs#10969) Commits ------- 7e4abee Fix undefined variable fromConstructor when passing context to getTypes
If passing context to getTypes, it checks value of $context['enable_constructor_extraction'] for true/false or the constructor value of enableConstructorExtraction and should then populate fromConstructor if necessary. The missing brackets around the first part of this check mean that fromConstructor is only applied if context is not set. This fixes the issuse described at [symfony/symfony-docs#10969](symfony/symfony-docs#10969)
I have read the discussion in symfony/symfony#25605 Plus, @javiereguiluz after your comment symfony/symfony#25605 (comment) there's a "Load More" button but if I click it, I get a 403. So I can't read further comments/explanations 😅 |
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.
ping @dunglas, would you have a look at this one? Thanks!
@@ -399,9 +402,15 @@ constructor. It supports return and scalar types for PHP 7. | |||
$reflectionExtractor->isReadable($class, $property); | |||
$reflectionExtractor->isWritable($class, $property); | |||
|
|||
// Initializable information | |||
// Initializable information. |
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.
Can be reverted
$reflectionExtractor->isInitializable($class, $property); | ||
|
||
// Constructor type information. |
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 dot can also be removed here
Hi @LS05! Thanks for creating the issue and providing value information + bug fixes around this topic! Seems like the bug you where describing is now fixed. After reading the original PR, I think this option is opt-in as it might create wrong type information (the argument name in the constructor doesn't have to be equal to the property name in the object - although that might be an edge-case imho). Are you by any chance able to update this PR with all new information you gathered? (so creating a working example and maybe showing both ways of enabling this option?) |
No description provided.