Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[HttpKernel] allow narrow type of not nullable getResponse when hasResponse has been called#58241

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
nicolas-grekas merged 1 commit intosymfony:7.2fromshyim:patch-2
Oct 9, 2024

Conversation

@shyim
Copy link
Contributor

@shyimshyim commentedSep 12, 2024
edited by nicolas-grekas
Loading

QA
Branch?7.3
Bug fix?no
New feature?no
Deprecations?no
Issues
LicenseMIT
if ($event->hasResponse()) {return$event->getResponse();}

PHPStan understands now inside the if that Response is not nullable anymore

@carsonbotcarsonbot added this to the5.4 milestoneSep 12, 2024
@shyimshyim changed the titleallow narrow type of not nullable getResponse when hasResponse has be…[HttpKernel] allow narrow type of not nullable getResponse when hasResponse has be…Sep 12, 2024
Copy link
Member

@xabbuhxabbuh left a comment

Choose a reason for hiding this comment

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

but for 7.2 as this is not a bugfix

@carsonbotcarsonbot changed the title[HttpKernel] allow narrow type of not nullable getResponse when hasResponse has be…allow narrow type of not nullable getResponse when hasResponse has be…Sep 12, 2024
@xabbuhxabbuh modified the milestones:5.4,7.2Sep 12, 2024
Copy link
Member

@derrabusderrabus left a comment

Choose a reason for hiding this comment

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

for 7.2

@wouterj
Copy link
Member

wouterj commentedSep 13, 2024
edited
Loading

As far as I know, we do not accept static analysis annotations that are not generally supported across Psalm, PHPStan and PhpStorm (see also thelist of accepted annotations in the Symfony standards).

It seems likeassert-if-true isnot supported by, at least, Psalm. So I'm 👎 , although the added annotation is correct (it might be worth submitting this as a stub to the PHPStan Symfony plugin).

@stof
Copy link
Member

Psalm does support theassert-if-true annotation. However, by default, Psalm does not memoize the type for getters, which is why it has no effect in your code snippet. Seehttps://psalm.dev/docs/running_psalm/configuration/#memoizemethodcallresults for the configuration andhttps://psalm.dev/r/561c4c3a87 for the same code snippet with this setting turned on.

phpstan has a different default than psalm regarding this option.

@wouterj
Copy link
Member

wouterj commentedSep 13, 2024
edited
Loading

Ah, of course. Thanks for correcting me,@stof.

Let's do it then 👍 , but with the@psalm- prefix to be consistent with the other annotations in the Symfony code base (although the prefix doesn't change anything in behavior).

@stof
Copy link
Member

stof commentedSep 13, 2024
edited
Loading

The only change in behavior is for the case where you write something wrong in the tag: both phpstan and psalm are reporting errors when writing an invalid tag with their own prefix while they silently discard an invalid tag using the prefix of the other tool (because maybe this tag is actually valid in the other tool and they don't have feature parity).
The recommended setup is to write annotation using the prefix of the tool that we use ourselves (and we are partially using psalm in our CI, which is why we use psalm prefixes)

@stof
Copy link
Member

For reference, seehttps://psalm.dev/docs/annotating_code/adding_assertions/#asserting-return-values-of-methods for the Psalm documentation about the exact conditions for@psalm-assert-if-true ... $this->someGetter() to work. There are cases that work withoutmemoizeMethodCallResults but this class does not correspond to those cases.

@nicolas-grekasnicolas-grekas changed the titleallow narrow type of not nullable getResponse when hasResponse has be…allow narrow type of not nullable getResponse when hasResponse has been calledOct 9, 2024
@carsonbotcarsonbot changed the titleallow narrow type of not nullable getResponse when hasResponse has been called[HttpKernel] allow narrow type of not nullable getResponse when hasResponse has been calledOct 9, 2024
@nicolas-grekas
Copy link
Member

Thank you@shyim.

@nicolas-grekasnicolas-grekas merged commit52f1436 intosymfony:7.2Oct 9, 2024
8 of 10 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@stofstofstof requested changes

@OskarStarkOskarStarkOskarStark approved these changes

@derrabusderrabusderrabus approved these changes

@xabbuhxabbuhxabbuh approved these changes

Assignees

No one assigned

Projects

None yet

Milestone

7.2

Development

Successfully merging this pull request may close these issues.

8 participants

@shyim@wouterj@stof@nicolas-grekas@OskarStark@derrabus@xabbuh@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp