Dark Mode

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

Comments

Add support to use short forms of type keywords#3139

Open
filips123 wants to merge 1 commit intosquizlabs:masterfrom
filips123:short-type-hints
Open

Add support to use short forms of type keywords#3139
filips123 wants to merge 1 commit intosquizlabs:masterfrom
filips123:short-type-hints

Conversation

Copy link
Contributor

filips123 commented Oct 10, 2020

This adds support to use short forms of type keywords in comments for function parameters and returns and variable types. It fixes #1864 and fixes #1434.

It adds useShortTypes property, which is by default false, to Squiz.Commenting.FunctionComment and Squiz.Commenting.VariableComment to allow users to use short type checks. If it is enabled, it will force short types in comments and suggest them when long ones are used.

P.S. I would appreciate if you add hacktoberfest-accepted label to this PR, so it will count for this year's Hacktoberfest.

ElvenSpellmaker, BigOHenry, andrii-pez, bramstroker, gdvisser, pprkut, ZebraNorth, ovillemain, Swennet, naoyukik, and 5 more reacted with thumbs up emoji
filips123 mentioned this pull request Oct 10, 2020
filips123 force-pushed the short-type-hints branch from 1d2170d to 87a6ef3 Compare October 26, 2020 15:00
halfpastfouram suggested changes Nov 18, 2020
* @var boolean
*/
public $useShortTypes = false;

Copy link

halfpastfouram Nov 18, 2020

Choose a reason for hiding this comment

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

Remove this empty line.

Suggested change

Copy link
Contributor

jrfnl Nov 18, 2020

Choose a reason for hiding this comment

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

Please don't request changes which are in violation with the coding standard used by the library.

'resource',
'callable',
];

Copy link

halfpastfouram Nov 18, 2020

Choose a reason for hiding this comment

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

Remove this empty line.

Suggested change

Copy link
Contributor

jrfnl Nov 18, 2020

Choose a reason for hiding this comment

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

Please don't request changes which are in violation with the coding standard used by the library.

*
* @var boolean
*/
public $useShortTypes = false;
Copy link

halfpastfouram Nov 18, 2020

Choose a reason for hiding this comment

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

Shouldn't this default to true due to PSR-12?

Copy link
Contributor Author

filips123 Nov 20, 2020

Choose a reason for hiding this comment

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

Shouldn't this default to true due to PSR-12?

Problem is that this might be considered as a breaking change. I'm not sure how this was done in the past, but maybe it should remain false in PHPCS 3.x and changed to true in 4.x.

Copy link

halfpastfouram Nov 20, 2020

Choose a reason for hiding this comment

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

I understand. In the mean time it's easy to just change that property in the config file.

Copy link

bramstroker commented Aug 2, 2021

Any chance to get this merged? Short return types are the way to go, especially because it does not comply to the rules of PSR-12 currently. "Short form of type keywords MUST be used i.e. bool instead of boolean, int instead of integer etc.".

gdvisser, SMillerDev, pprkut, plamen-dimitrov06, yuki-matsui-at-geniee, daggerhart, ovillemain, Swennet, rotdrop, and naopusyu reacted with thumbs up emoji

Copy link

ZebraNorth commented Dec 20, 2021

Until such time as this can be merged, I've added a workaround here: https://packagist.org/packages/zebra-north/phpcs-short-types

It's not a proper fix, it would be great if this PR could be merged.

bmitch, Swennet, rotdrop, drdrak3, naopusyu, and quasipickle reacted with thumbs up emoji

Copy link

drdrak3 commented Dec 2, 2022

I would love for this to be merged, we are using PHPStorm and it automatically (and correctly) uses short types which we have to manually update to pass our code sniffers

naopusyu, Craige, and marcelfolaron reacted with thumbs up emoji

Copy link

richard-hp commented Oct 20, 2023

Merging this in would be useful

Copy link

Justintime50 commented Dec 17, 2025

Would definitely love to see this merged and released! Super odd to have code type hints be one thing and docblock types not enforced to match.

Copy link
Contributor

fredden commented Dec 29, 2025

@Justintime50 it is very unlikely that this will be merged here. See #3932.

Justintime50 reacted with thumbs up emoji

Copy link

Justintime50 commented Jan 4, 2026

Seeing as it's unlikely this makes it into PHPCS, I've created a sniff that enforces short scalar type names with auto-fix as well: https://github.com/Justintime50/phpcs-short-scalar-types. This can be used in lieu of the missing 1st party support.

This sniff will error if boolean or integer are used in comments/docblocks and instead instruct to use bool and int. Run the auto-fixer to cleanup a project real quick.

Hope it's helpful for future travelers!

Copy link
Contributor Author

filips123 commented Jan 4, 2026

@fredden Should this PR then be moved to the new repository?

Justintime50 reacted with rocket emoji

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

Reviewers

jrfnl jrfnl left review comments

+1 more reviewer

halfpastfouram halfpastfouram requested changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Type hinting: bool or boolean IncorrectParamVarName: Problem with short and long types (int / integer)

9 participants