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

Commits on Apr 18, 2023

  1. Move is_class_object_call() utility method to dedicated `ContextHel…

    …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.
    jrfnl committed Apr 18, 2023
    Configuration menu
    Copy the full SHA
    34f1ada View commit details
    Browse the repository at this point in the history
  2. 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.
    jrfnl committed Apr 18, 2023
    Configuration menu
    Copy the full SHA
    40d5ac9 View commit details
    Browse the repository at this point in the history