-
-
Notifications
You must be signed in to change notification settings - Fork 12
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
Improve psalm type inference, add missing type annotations #36
Conversation
Reduces psalm's baseline to almost nothing with 99.7% type coverage Signed-off-by: George Steel <george@net-glue.co.uk>
Signed-off-by: George Steel <george@net-glue.co.uk>
Signed-off-by: George Steel <george@net-glue.co.uk>
90bda81
to
3ad3449
Compare
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.
LGTM, thanks @gsteel!
*/ | ||
private function cleanKeysForXml(array $input): array | ||
{ | ||
$return = []; | ||
/** @psalm-var mixed $value */ |
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.
@Ocramius This is btw why I disabled MixedAssignment
in my projects. This is 100% useless and its not properly typable and thus MixedAssignment
is unnecessary.
There are even discussion in the psalm repository where they talk about removing MixedAssignment
at all as it is not a real issue.
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.
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.
IMO worth investigating/baselining: I have mixed
stuff so rarely nowadays, that this is okay with baselines.
A mixed
assignment in one of my own projects is usually a bug or design mistake.
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.
Imho a mixed assignment in projects is almost "standard" as you have some stuff like:
$value = $request->getAttribute('whatever');
There is almost no way to properly have types for that unless you put that to a service which extracts attributes to DTOs. Imho thats usually overengineered and thus I am fine with something like:
$value = $request->getAttribute('whatever'); // mixed
Assert::positiveInt($value);
Same for console applications providing stuff via STDIN. Youcan extract arguments which are properly typed in symfony/console using addArgument
while psalm is still not able to understand what the value is when read.
And that is fine. 🤷🏼♂️
If you do not pass mixed
through half of your application, thats okayish imho.
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 only ever pass those into an upcast tool, like Psl\Type
: laminas/automatic-releases
is an example of that
Description
Reduces psalm's baseline to almost nothing with 99.7% type coverage