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

Add support to use short forms of type keywords #3139

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

filips123
Copy link
Contributor

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.

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

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

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',
];

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

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;

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

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.

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.

@bramstroker
Copy link

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.".

@ZebraNorth
Copy link

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.

@drdrak3
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

@richard-hp
Copy link

Merging this in would be useful

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

Successfully merging this pull request may close these issues.

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