Skip to content

Conversation

@jrfnl
Copy link
Member

@jrfnl jrfnl commented Jun 6, 2022

This commit splits the TextStrings::getCompleteTextString() method into three distinct methods:

  • TextStrings::getCompleteTextString() will still retrieve the complete text of a potentially multi-line text string (no BC-break).
  • TextStrings::getEndOfCompleteTextString() can be used to retrieve the last token for a potentially multi-line text string.
    This method should be preferred when the sniff wants to "skip over" the additional tokens in the text string as part of its process logic.
  • TextStrings::getEndOfDoubleQuotedString() to specifically handle the PHPCS bug identified and reported in Tokenizer/PHP: bug fix for double quoted strings using ${ squizlabs/PHP_CodeSniffer#3604.
    This method is useful when a sniff does want to examine each T_DOUBLE_QUOTED_STRING token individually as they should have been tokenized and will allow for reporting issues on the correct line, while this would be much more difficult when using the TextStrings::getCompleteTextString() method.

Includes:

  • Renaming the GetCompleteTextString3604Test to GetEndOfDoubleQuotedStringTest.
  • Additional tests documenting and safeguarding the handling of problem embeds in multi-line text strings.
  • Additional tests covering the "new" parts of this code change.

This commit splits the `TextStrings::getCompleteTextString()` method into three distinct methods:
* `TextStrings::getCompleteTextString()` will still retrieve the complete text of a potentially multi-line text string (no BC-break).
* `TextStrings::getEndOfCompleteTextString()` can be used to retrieve the last token for a potentially multi-line text string.
    This method should be preferred when the sniff wants to "skip over" the additional tokens in the text string as part of its process logic.
* `TextStrings::getEndOfDoubleQuotedString()` to  specifically handle the PHPCS bug identified and reported in squizlabs/PHP_CodeSniffer 3604.
    This method is useful when a sniff does want to examine each `T_DOUBLE_QUOTED_STRING` token individually as they _should_ have been tokenized and will allow for reporting issues on the correct line, while this would be much more difficult when using the `TextStrings::getCompleteTextString()` method.

Includes:
* Renaming the `GetCompleteTextString3604Test` to `GetEndOfDoubleQuotedStringTest`.
* Additional tests documenting and safeguarding the handling of problem embeds in multi-line text strings.
* Additional tests covering the "new" parts of this code change.
@jrfnl jrfnl added this to the 1.0.0-alpha4 milestone Jun 6, 2022
@jrfnl jrfnl merged commit 0db9570 into develop Jun 6, 2022
@jrfnl jrfnl deleted the textstrings/split-getcompletetextstring-method branch June 6, 2022 23:43
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