Extension point for specifying class method parameter types based on an attribute #14609
Unanswered
GottemHams
asked this question in
Support
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I found a number of other similar discussions/issues about this general topic, but none of them are exactly about my specific use case so let's try a new discussion. :>
I'm trying to inform PHPStan that
$restis always alist<string>in this method:I'm mostly trying to avoid having to repeat
@param list<string>everywhere, since it can always be inferred from the attribute. Unlike pretty much all the other issues I found, I only deal with primitives so missing out on IDE autocompletion is not a real concern. At most it might complain that you're passing implicit or "incompatible" types somewhere, like when usingarray_map(strtolower(...), $rest). But at least PHPStan would know what the actual type is and can still properly analyse the method.missingType.iterableValueis not a viable option for similar reasons, as PHPStan still wouldn't know the type so it'll still report an error on the samearray_map()call. Not to mention that ignoring errors can really only lead to bugs, so I'm trying to avoid that as much as possible in the first place.:first(/:rest+)and that would require a?list<string>type. Trying to represent this with a variadic is incorrect: it impliesNULLcan appear anywhere in the actual values, which is not the case.ExpressionTypeResolverExtensionlike a previous discussion we had, but in this case it's not actually anExprso that's never going to work. The only real thing I can think of is using such an extension to change the type based on specific variable accesses, but PHPStan still wouldn't know the type at the start of the method so it'll still reportmissingType.iterableValuethere.Is there a realistic chance of an extension point being made available that allows me to do this one way or another? And if not, are there even any viable alternatives (besides writing
@param list<string>of course)?Beta Was this translation helpful? Give feedback.
All reactions