Skip to content

Conversation

@jrfnl
Copy link
Member

@jrfnl jrfnl commented Jun 6, 2022

This introduces three new methods to the PHPCSUtils\Utils\TextStrings class.

Methods:

  • getEmbeds() - to retrieve embedded variables and expressions from an arbitrary string, typically the contents of a T_DOUBLE_QUOTED_STRING or T_HEREDOC. Returns an array of the variables/expression recognized as strings with the offset within the string at which the embed was found as the keys.
  • stripEmbeds() - strip embedded variables/expression from an arbitrary string, typically the contents of a T_DOUBLE_QUOTED_STRING or T_HEREDOC. Returns the adjusted string.
  • getStripEmbeds() - the actual "worker" method which does both of the above in one go.
    This method is public for those rare cases where both the embeds as well as the stripped text is needed.

These methods support all types of variable/expression embedding as supported by PHP. Please report edge cases if you run into one.

These methods are much improved versions of the methods which have previously been battle-tested in various forms in the PHPCompatibility and the WordPressCS standards.

Includes extensive, dedicated unit tests.

This introduces three new methods to the PHPCSUtils\Utils\TextStrings class.

Methods:
* `getEmbeds()` - to retrieve embedded variables and expressions from an arbitrary string, typically the contents of a `T_DOUBLE_QUOTED_STRING` or `T_HEREDOC`. Returns an array of the variables/expression recognized as strings with the offset within the string at which the embed was found as the keys.
* `stripEmbeds()` - strip embedded variables/expression from an arbitrary string, typically the contents of a `T_DOUBLE_QUOTED_STRING` or `T_HEREDOC`. Returns the adjusted string.
* `getStripEmbeds()` - the actual "worker" method which does both of the above in one go.
    This method is `public` for those rare cases where both the embeds as well as the stripped text is needed.

These methods support all types of variable/expression embedding as supported by PHP. Please report edge cases if you run into one.

These methods are much improved versions of the methods which have previously been battle-tested in various forms in the PHPCompatibility and the WordPressCS standards.

Includes extensive, dedicated unit tests.
@jrfnl
Copy link
Member Author

jrfnl commented Jun 7, 2022

Note: the code coverage going down is a bug in Coveralls reporting. The build on the develop branch after the merge should confirm that code coverage has actually remained the same or even gone up.

@jrfnl jrfnl merged commit 692c248 into develop Jun 7, 2022
@jrfnl jrfnl deleted the textstrings/new-methods-handling-embedded-vars-and-expressions branch June 7, 2022 09:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

2 participants