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
added phpstan ConfigReturnTypeExtension #10635
Conversation
at this early stage, this extension already provides enough type-inference to detect type of ca3b874
|
@Seldaek you are more familiar with the composer schema... are you ok with finishing the PR from this point? feel free to ping me regarding phpstan/phpstan-extension related questions. |
Ok sure, thanks! |
Looks promising already. I think it could make sense to ship a phpstan config with composer, meant for include in e.g. plugin projects which also use phpstan, so they also benefit from the static analysis enhancements. if you have questions left, feel free to ask |
Yeah good point, did that now, ready to merge IMO, this works great for Config! Thanks for the help getting started. |
@Seldaek not sure we missed something, but it seems atm the do we need to whitelist the |
if ($addlPropType !== null) { | ||
$types[] = new ArrayType(TypeCombinator::union(new StringType(), ...$keyNames), TypeCombinator::union($addlPropType, ...$valTypes)); | ||
} else { | ||
$types[] = new ConstantArrayType($keyNames, $valTypes); |
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.
for non-required properties, the keys should be marked as optional keys (through the 4th argument)
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.
I can gladly open a PR adapting that. I didn't use JSON schema often yet, but I don't see many required
fields there which would make almost all keys optional. I guess this is not the expected outcome, is it?
Ah and I just saw that apparently non-required props are already unioned with a NullType (still non-optional in the ConstantArray though). I'll wait before I adapt anything here.
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.
This had less impact than I thought: #10815
Btw, I'm not sure an optional key actually allows |
I think my point was more that if it's optional and you call get() on it it may return null. |
But this is about a subkey of an array shape. You cannot call |
Yes I can see that, for that case I don't know.. maybe I was lost in recursion and this doesn't make sense here. I don't recall tbh. |
as discussed in ca3b874#commitcomment-68913659