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

Core: move rules related to object instantiations from Extra to Core #2133

Merged
merged 2 commits into from
Dec 8, 2022

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Dec 7, 2022

Core: move rules related to object instantiations from Extra to Core

  1. When instantiating a new instance of an object, parenthesis must always be used, even when not strictly necessary.
  2. There should be no space between the name of the class being instantiated and the opening parenthesis.

Note: the spacing inside the parentheses when instantiating anonymous classes will not (yet) be checked by the PEAR.Functions.FunctionCallSignature sniff. A PR is open upstream to add support for this: squizlabs/PHP_CodeSniffer#3636
Once the upstream PR has been merged, WPCS will automatically inherit the support as this sniff is already included in WPCS.

The following will no longer be checked by WPCS:

  1. Assigning the return value of an object instantiation by reference is not allowed.

This is a parse error since PHP 7.0, so should not be the concern of WPCS (and hasn't been added to the handbook for the same reason). See: https://3v4l.org/W2Qj6


As discussed in #1884, this means that JS support for checking object instantiations will be dropped, but as WPCS is generally not used for checking JS code, this should not be a problem.


Refs and related issues:

Fixes #1884
Fixes #2033

Remove the Classes/ClassInstantiation sniff

... as it is now no longer used.

jrfnl added 2 commits December 7, 2022 22:50
> 1.  When instantiating a new instance of an object, parenthesis must always be used, even when not strictly necessary.
> 2. There should be no space between the name of the class being instantiated and the opening parenthesis.

Note: the spacing inside the parentheses when instantiating anonymous classes will not (yet) be checked by the `PEAR.Functions.FunctionCallSignature` sniff. A PR is open upstream to add support for this: squizlabs/PHP_CodeSniffer 3636
Once the upstream PR has been merged, WPCS will automatically inherit the support as this sniff is already included in WPCS.

The following will no longer be checked by WPCS:
> 3. Assigning the return value of an object instantiation by reference is not allowed.

This is a parse error since PHP 7.0, so should not be the concern of WPCS (and hasn't been added to the handbook for the same reason). See: https://3v4l.org/W2Qj6

---
As discussed in 1884, this means that JS support for checking object instantiations will be dropped, but as WPCS is generally not used for checking JS code, this should not be a problem.
---

Refs and related issues:
* https://make.wordpress.org/core/2020/03/20/updating-the-coding-standards-for-modern-php/ - Object instantiation section
* https://developer.wordpress.org/coding-standards/wordpress-coding-standards/php/#object-instantiation
* WordPress/wpcs-docs 109
* WordPress/WordPress-Coding-Standards 919
* WordPress/WordPress-Coding-Standards 1033
* WordPress/WordPress-Coding-Standards 1721
* squizlabs/PHP_CodeSniffer 3200
* squizlabs/PHP_CodeSniffer 3636 (not yet merged)
* PHPCSStandards/PHPCSExtra 76
* PHPCSStandards/PHPCSExtra 120

Fixes 1884
Fixes 2033
... as it is now no longer used.
Copy link
Member

@GaryJones GaryJones left a comment

Choose a reason for hiding this comment

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

@dingo-d dingo-d merged commit 2880e5b into develop Dec 8, 2022
@dingo-d dingo-d deleted the feature/core-move-object-instantiation-rules branch December 8, 2022 07:56
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.

Fixer for missing parentheses adds them to the wrong place in one case Split the ClassInstantiation sniff
3 participants