Skip to content
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

Merged
merged 3 commits into from
Jan 10, 2023

Conversation

gsteel
Copy link
Member

@gsteel gsteel commented Jan 10, 2023

Q A
Documentation yes
QA yes

Description

Reduces psalm's baseline to almost nothing with 99.7% type coverage

Reduces psalm's baseline to almost nothing with 99.7% type coverage

Signed-off-by: George Steel <george@net-glue.co.uk>
@gsteel gsteel added the Enhancement New feature or request label Jan 10, 2023
@gsteel gsteel added this to the 1.11.0 milestone Jan 10, 2023
Signed-off-by: George Steel <george@net-glue.co.uk>
Signed-off-by: George Steel <george@net-glue.co.uk>
Copy link
Member

@Ocramius Ocramius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks @gsteel!

@Ocramius Ocramius self-assigned this Jan 10, 2023
@Ocramius Ocramius merged commit 20ae0fc into mezzio:1.11.x Jan 10, 2023
*/
private function cleanKeysForXml(array $input): array
{
$return = [];
/** @psalm-var mixed $value */
Copy link
Member

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

@Ocramius Ocramius Jan 10, 2023

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.

Copy link
Member

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.

Copy link
Member

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

@gsteel gsteel deleted the feature/psalm-hack branch January 10, 2023 12:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants