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

3.0: Move "interpolated variable" related utilities to dedicated TextStringHelper #2051

Merged
merged 1 commit into from
May 16, 2022

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented May 15, 2022

The "interpolated variable" related utilities are only used by a small set of sniffs, so are better placed in a dedicated class.

This commit moves the REGEX_COMPLEX_VARS constant, the get_interpolated_variables() method and the strip_interpolated_variables() method to a new WordPressCS\WordPress\Helpers\TextStringHelper and starts using that class in the relevant sniffs.

In contrast to some of the other "move methods out of the Sniff class" PRs, these methods have been moved to a class and made static - instead of moved to a trait.
The reason for this difference is that the methods in other "moves" are setting properties which the sniff classes would need access to, while these methods are 100% stand-alone.

Note:
It is expected for PHPCSUtils to have dedicated methods for the same at some point in the future. If/when those methods become available, it is recommended for the sniffs to start using the PHPCSUtils methods and for this class to be deprecated and removed in the next major release.

Also note that PHP 8.2 will be making changes to the kind of interpolation supported by PHP. This will need further investigation at a future point in time (probably in PHPCSUtils rather than here), if nothing else to ensure that what was supported in PHP prior to PHP 8.2 is fully supported by these methods (which is probably not the case at this moment).
Ref: https://wiki.php.net/rfc/deprecate_dollar_brace_string_interpolation

Related to #1465

…ngHelper`

The "interpolated variable" related utilities are only used by a small set of sniffs, so are better placed in a dedicated class.

This commit moves the `REGEX_COMPLEX_VARS` constant, the `get_interpolated_variables()` method and the `strip_interpolated_variables()` method to a new `WordPressCS\WordPress\Helpers\TextStringHelper` and starts using that class in the relevant sniffs.

In contrast to some of the other "move methods out of the Sniff class" PRs, these methods have been moved to a class and made `static` - instead of moved to a `trait`.
The reason for this difference is that the methods in other "moves" are setting properties which the sniff classes would need access to, while these methods are 100% stand-alone.

**Note**:
It is expected for PHPCSUtils to have dedicated methods for the same at some point in the future. If/when those methods become available, it is recommended for the sniffs to start using the PHPCSUtils methods and for this class to be deprecated and removed in the next major release.

Also note that PHP 8.2 will be making changes to the kind of interpolation supported by PHP. This will need further investigation at a future point in time (probably in PHPCSUtils rather than here), if nothing else to ensure that what was supported in PHP prior to PHP 8.2 is fully supported by these methods (which is probably not the case at this moment).
Ref: https://wiki.php.net/rfc/deprecate_dollar_brace_string_interpolation

Related to 1465
@jrfnl jrfnl force-pushed the feature/1465-new-textstringhelper-class branch from a042596 to 76f3376 Compare May 16, 2022 11:38
@dingo-d dingo-d merged commit 8ee4394 into develop May 16, 2022
@dingo-d dingo-d deleted the feature/1465-new-textstringhelper-class branch May 16, 2022 12:40
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.

3 participants