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_token_namespaced() utility method to dedicated ContextHelper + minor simplifications #2227

Merged
merged 2 commits into from
Apr 19, 2023

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Apr 19, 2023

Next one in the series

Move is_token_namespaced() utility method to dedicated ContextHelper

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

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

Related to #1465

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

ContextHelper::is_token_namespaced(): minor simplifications

  • A non-inline HTML token will always have another non-empty token before it, if nothing else, the PHP open tag, so checking if $prev is false is redundant.
  • Same for the second time this is done, as the same applies for the T_NS_SEPARATOR token.

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

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

Related to 1465

This method is tested via the `WordPress.WP.DiscouragedFunctions` sniff.
* A non-inline HTML token will always have another non-empty token before it, if nothing else, the PHP open tag, so checking if `$prev` is `false` is redundant.
* Same for the second time this is done, as the same applies for the `T_NS_SEPARATOR` token.
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.

@GaryJones GaryJones merged commit 6757824 into develop Apr 19, 2023
35 checks passed
@GaryJones GaryJones deleted the feature/move-istokennamespaced-to-helper-class branch April 19, 2023 11: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