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

Appearance settings

Fix return type of Header::all #46613

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

Closed
wants to merge 2 commits into from
Closed

Fix return type of Header::all #46613

wants to merge 2 commits into from

Conversation

Seldaek
Copy link
Member

@Seldaek Seldaek commented Jun 7, 2022

Q A
Branch? 5.4
Bug fix? yes
New feature? no
Deprecations? no
Tickets Fix phpstan/phpstan-symfony#264
License MIT
Doc PR symfony/symfony-docs#...

cc @derrabus

@@ -65,7 +65,7 @@ public function __toString()
*
* @param string|null $key The name of the headers to return or null to get them all
*
* @return array<string, array<int, string|null>>|array<int, string|null>
* @return $key is null ? array<string, array<int, string|null>> : array<int, string|null>
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* @return $key is null ? array<string, array<int, string|null>> : array<int, string|null>
* @return ($key is null ? array<string, array<int, string|null>> : array<int, string|null>)

See https://phpstan.org/r/18e18b32-1cc3-4647-875b-c756ad1ad4d7

Also, to keep IDE support I would recommend

Suggested change
* @return $key is null ? array<string, array<int, string|null>> : array<int, string|null>
* @return array<string, array<int, string|null>>|array<int, string|null>
* @phpstan-return ($key is null ? array<string, array<int, string|null>> : array<int, string|null>)

(or psalm-return if preferred)

Copy link
Member Author

Choose a reason for hiding this comment

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

Applied the first fix, thanks.

The second I would agree but I think it's again symfony policy so leaving it as is.

Co-authored-by: Vincent Langlet <VincentLanglet@users.noreply.github.com>
@derrabus
Copy link
Member

derrabus commented Jun 7, 2022

AFAIK (cc @nicolas-grekas) we only annotate types that have broad tooling support. This is certainly not the case for this kind of conditional types. And we don't use vendor-prefixed annotations either.

If that issue could be solved by the Symfony plugin for Psalm, I think I'd prefer that way.

@VincentLanglet
Copy link
Contributor

If that issue could be solved by the Symfony plugin for Psalm, I think I'd prefer that way.

Stub with this conditionnal return type can be added in both phpstan-symfony and psalm-symfony plugin yes.

AFAIK (cc @nicolas-grekas) we only annotate types that have broad tooling support. This is certainly not the case for this kind of conditional types. And we don't use vendor-prefixed annotations either.

Is there any plan to start using prefixed annotations later ? Or what is the reason to not to ?

@Seldaek
Copy link
Member Author

Seldaek commented Jun 7, 2022

@nicolas-grekas IMO this policy is a mistake at this point. It might have made sense a while back but PHPStan usage is spreading more and more, and having type annotations shipped with the framework would make more sense. It ensures the types are always in sync with the Symfony version and they would also benefit Symfony itself in terms of added static analysis capability.

I've seen a similar thing happen in the TypeScript ecosystem where at first typings packages where provided to type things from the outside, and then eventually all major packages started shipping their own type definitions or even switching their source completely to typescript.

PHPStan is now a very established tool, and Psalm also reads @phpstan-x annotations (and vice-versa), and PHPStorm is adding support for more and more types in every release, so I think the "broad tooling support" argument is maybe moot?

Just my 2c :)

@derrabus
Copy link
Member

derrabus commented Jun 7, 2022

Is there any plan to start using prefixed annotations later ?

There are no plans yet.

Or what is the reason to not to ?

We use Psalm merely as a code review tool these days. If you want to dicuss an initiaive to make the codebase more accessible for SA tools, it would maybe be better to discuss this in a separate issue first.

@Seldaek
Copy link
Member Author

Seldaek commented Jun 7, 2022

Yeah, I don't have time for that crusade, so closing here, moved to phpstan/phpstan-symfony#282 - but for the record my point above stands.

@Seldaek Seldaek closed this Jun 7, 2022
@Seldaek Seldaek deleted the patch-21 branch June 7, 2022 11:52
@nicolas-grekas
Copy link
Member

For the record, having phpstan+psalm+phpstorm support for the syntax is our current bar.

@VincentLanglet
Copy link
Contributor

For the record, having phpstan+psalm+phpstorm support for the syntax is our current bar.

Since PHPStorm 2022.3.1, the conditional return is supported by PHPStorm.
https://youtrack.jetbrains.com/issue/WI-66465/Support-parsing-of-PhpStans-conditional-return-types

So would the PR be accepted if re-opened ? @nicolas-grekas

@ro0NL
Copy link
Contributor

ro0NL commented Jan 17, 2023

do phpstan+psalm share same syntax now? IMHO it's essential for maintenance. Unless it's not, and we choose vendor prefixes, for what is a single language :D

@nicolas-grekas
Copy link
Member

Please resubmit after checking with the main tools yes.

@VincentLanglet
Copy link
Contributor

Sure, #49007

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.