PHP-CS-Fixer icon indicating copy to clipboard operation
PHP-CS-Fixer copied to clipboard

Normalize `null|Foo` vs `?Foo` in phpDoc

Open keradus opened this issue 7 years ago • 18 comments

In #7002 nullability normalisation was introduced for native types. We also should have solution for phpDoc.

For reference see here.

keradus avatar Feb 22 '18 14:02 keradus

why the downvote, could be a configurable fixer for one of the two styles?

SpacePossum avatar Feb 22 '18 16:02 SpacePossum

Could be. My downvote is for a fixer that would change Foo|null to ?Foo. I'm fine with a fixer doing the opposite change though I don't think it's worth it: I never saw such syntax in PHPDocs except here.

julienfalque avatar Feb 22 '18 17:02 julienfalque

I've never seen ?Foo, only null|foo, would like to be proven wrong though

ntzm avatar Feb 22 '18 18:02 ntzm

yes, would be nice if fixer could go both ways, so one could always unify his codebase.

there are not that much php 7.1+ codebase yet ;)

keradus avatar Feb 22 '18 21:02 keradus

This is implemented now, and can be closed.

GrahamCampbell avatar Jan 02 '20 13:01 GrahamCampbell

By the nullable_type_declaration_for_default_null_value fixer.

GrahamCampbell avatar Jan 02 '20 13:01 GrahamCampbell

nullable_type_declaration_for_default_null_value is different: it updates the real type declaration, while this feature request is about PHPDoc syntax, i.e.:

/** @param Foo|null $foo */

vs.

/** @param ?Foo $foo */

julienfalque avatar Jan 02 '20 14:01 julienfalque

Oh, I see.

GrahamCampbell avatar Jan 02 '20 14:01 GrahamCampbell

Since PHP now supports union types, I think such PHPDocs will disappear entirely and we won't need such rule anymore. Shall we close?

julienfalque avatar May 21 '21 07:05 julienfalque

do we have a rule to move that PHPDoc to PHP type declaration?

keradus avatar Jul 26 '21 19:07 keradus

Since PHP now supports union types, I think such PHPDocs will disappear entirely and we won't need such rule anymore.

I don't think so! We still can't express things like ?non-empty-list<non-empty-string> in PHP types, but this is a valid specialism of array|null according to the type system specified by Psalm.

GrahamCampbell avatar Jul 26 '21 21:07 GrahamCampbell

I'm working on an implementation of this feature and hopefully will provide a PR soon.

pkly avatar May 20 '23 17:05 pkly

Resolved via #7002

pkly avatar Jul 11 '23 08:07 pkly

This is for PHPDocs, not for type declarations. Should be reopened.

paulbalandan avatar Jul 11 '23 09:07 paulbalandan

Since this issue has not had any activity within the last 90 days, I have marked it as stale.

The purpose of this action is to enforce backlog review once in a while. This is mostly for maintainers and helps with keeping repository in good condition, because stale issues and PRs can accumulate over time and make it harder for others to find relevant information. It is also possible that some changes has been made to the repo already, and issue or PR became outdated, but wasn't closed for some reason. This action helps with periodic review and closing of such stale items in automated way.

You may let maintainers handle this or verify current relevancy by yourself, to help with re-triage. Any activity will remove stale label so it won't be automatically closed at this point.

I will close it if no further activity occurs within the next 30 days.

github-actions[bot] avatar Oct 22 '23 12:10 github-actions[bot]

Since this issue has not had any activity within the last 90 days, I have marked it as stale.

The purpose of this action is to enforce backlog review once in a while. This is mostly for maintainers and helps with keeping repository in good condition, because stale issues and PRs can accumulate over time and make it harder for others to find relevant information. It is also possible that some changes has been made to the repo already, and issue or PR became outdated, but wasn't closed for some reason. This action helps with periodic review and closing of such stale items in automated way.

You may let maintainers handle this or verify current relevancy by yourself, to help with re-triage. Any activity will remove stale label so it won't be automatically closed at this point.

I will close it if no further activity occurs within the next 30 days.

github-actions[bot] avatar Jan 21 '24 12:01 github-actions[bot]

Since this issue has not had any activity within the last 90 days, I have marked it as stale.

The purpose of this action is to enforce backlog review once in a while. This is mostly for maintainers and helps with keeping repository in good condition, because stale issues and PRs can accumulate over time and make it harder for others to find relevant information. It is also possible that some changes has been made to the repo already, and issue or PR became outdated, but wasn't closed for some reason. This action helps with periodic review and closing of such stale items in automated way.

You may let maintainers handle this or verify current relevancy by yourself, to help with re-triage. Any activity will remove stale label so it won't be automatically closed at this point.

I will close it if no further activity occurs within the next 30 days.

github-actions[bot] avatar May 04 '24 12:05 github-actions[bot]

Since this issue has not had any activity within the last 90 days, I have marked it as stale.

The purpose of this action is to enforce backlog review once in a while. This is mostly for maintainers and helps with keeping repository in good condition, because stale issues and PRs can accumulate over time and make it harder for others to find relevant information. It is also possible that some changes has been made to the repo already, and issue or PR became outdated, but wasn't closed for some reason. This action helps with periodic review and closing of such stale items in automated way.

You may let maintainers handle this or verify current relevancy by yourself, to help with re-triage. Any activity will remove stale label so it won't be automatically closed at this point.

I will close it if no further activity occurs within the next 30 days.

github-actions[bot] avatar Aug 03 '24 12:08 github-actions[bot]