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

TextStrings::getCompleteTextString(): split into three methods #320

Merged
merged 1 commit into from Jun 6, 2022

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant