3.0: Move "interpolated variable" related utilities to dedicated TextStringHelper
#2051
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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, theget_interpolated_variables()
method and thestrip_interpolated_variables()
method to a newWordPressCS\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 atrait
.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