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

Move is_class_object_call() utility method to dedicated ContextHelper + support nullsafe object operator #2226

Merged
merged 2 commits into from
Apr 19, 2023

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Apr 18, 2023

Note: this PR is part of a series moving various method to this new ContextHelper class. Pulling each bit separately to allow for easier reviewing.

Move is_class_object_call() utility method to dedicated ContextHelper

The is_class_object_call() utility method is only used by a small set of sniffs, so is better placed in a dedicated class.

This commit moves the is_class_object_call() method to the new WordPressCS\WordPress\Helpers\ContextHelper class and starts using that class in the relevant sniffs.

The method has also been renamed to has_object_operator_before() as it doesn't actually check if something is a (method) call, just that something OO (method, constant, property) is being accessed.

Related to #1465

This method is tested via the WordPress.WP.DiscouragedFunctions sniff.

ContextHelper::has_object_operator_before(): simplify/use PHPCSUtils/support PHP 8.0 nullsafe object operator

  • A non-inline HTML token will always have another non-empty token before it, if nothing else, the PHP open tag, so checking if $before is false is redundant.
  • Implement use of the Collections::objectOperators() token group, which includes the PHP 8.0+ nullsafe object operator.

Note: this automatically adds support for the nullsafe object operator to all sniffs using this method, either directly or indirectly.

Includes test via the WordPress.WP.DiscouragedFunctions sniff.

…per`

The `is_class_object_call()` utility method is only used by a small set of sniffs, so is better placed in a dedicated class.

This commit moves the `is_class_object_call()` method to the new `WordPressCS\WordPress\Helpers\ContextHelper` class and starts using that class in the relevant sniffs.

The method has also been renamed to `has_object_operator_before()` as it doesn't actually check if something is a (method) _call_, just that something OO (method, constant, property) is being accessed.

Related to 1465

This method is tested via the `WordPress.WP.DiscouragedFunctions` sniff.
…support PHP 8.0 nullsafe object operator

* A non-inline HTML token will always have another non-empty token before it, if nothing else, the PHP open tag, so checking if `$before` is `false` is redundant.
* Implement use of the `Collections::objectOperators()` token group, which includes the PHP 8.0+ nullsafe object operator.

_Note: this automatically adds support for the nullsafe object operator to all sniffs using this method, either directly or indirectly._

Includes test via the `WordPress.WP.DiscouragedFunctions` sniff.
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 942bb72 into develop Apr 19, 2023
@dingo-d dingo-d deleted the feature/move-is-class-object-call-to-helper-class branch April 19, 2023 08:45
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.

None yet

3 participants