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
WIP/RFC - Extend support for treatPhpDocTypesAsCertain
to more expressions (initial attempt)
#1627
Conversation
…s (first attempt)
It's not for me to decide obviously but I like the new helper method. I'd make it private and use it internally wherever possible to simplify things. But better wait for Ondrej's opinion there. Regarding the test I should be able to help out - you have to add a test for the rule that errors in the linked issue. That test class most likely has a private prop that you can use to enable or disable "treat phpdoc types as certain". And I assume here it should show that no errors are reported. |
My main interest is to have
The benefit I'm looking for here is to be able to implement a rule that tells us when /** @var string|null $var */
$var = $this->returnsString(); We'd know the And once we have that, any phpstan-src/src/Rules/Comparison/ConstantConditionRuleHelper.php Lines 72 to 76 in bd971db
I also realize that the phpstan-src/src/Analyser/MutatingScope.php Lines 734 to 738 in bd971db
MutatingScope::getNativeType() is fully implemented, it won't be necessary.
Of course this is a massive undertaking and will need like 1k-2k lines of code at least. |
I'm not sure if my pull request is on the right track, but I have a WIP pull request that may help? and is related to this. |
My pull request is mainly trying to solve 2. that ondrej mentions in #1627 (comment) |
sorry to hijack this, I thought it's a good place for further getType / getNativeType questions. I noticed that I guess the question is: Should |
@herndlm I'm not sure about these arguments. Please try to find any wrong behaviour with phpstan.org/try and open a separate issue for it. |
Hi, I'm cleaning up old and stale PRs. Please send a new PR if you're still interested, thanks. This attempt doesn't work for us, there's some work being done in #1802. |
WIP/RFC - do not merge!
I took a crack at the issue phpstan/phpstan#7075 (also as phpstan/phpstan#7795) but I have a lot of doubts
about this patch, so I'm posting the PR to get some initial feedback in particular
on the following points:
1) What's the difference between
promoteNativeTypes()
, and theconditional use of
getType()
vsgetNativeType()
based on the settingtreatPhpDocTypesAsCertain
?2) Should we unify all of this for all expressions? It sounds like there
are more cases where we should honor
treatPhpDocTypesAsCertain
, that why Iintroduced the new
getTypeOrNative()
function. So if this is the way to go,I would first refactor all existing cases to use this newly introduced method
3) What do you think about the name
getTypeOrNative()
? I don't like it butI still would like something short as it's going to be used a lot. Also, should
it be private, protected, or public?
4) This change broke zero tests, that means new tests should be introduced
before making this change. Any recommended strategy? Where should they go?
How should they look like? They clearly need to be ran twice with the different
configuration.