PHPCSUtils

TextStrings

Utility functions for working with text string tokens.

Tags
since
1.0.0

Table of Contents

getCompleteTextString()  : string
Get the complete contents of a - potentially multi-line - text string.
stripQuotes()  : string
Strip text delimiter quotes from an arbitrary string.

Methods

getCompleteTextString()

Get the complete contents of a - potentially multi-line - text string.

public static getCompleteTextString(File $phpcsFile, int $stackPtr[, bool $stripQuotes = true ]) : string

PHPCS tokenizes multi-line text strings with a single token for each line. This method can be used to retrieve the text string as it would be received and processed in PHP itself.

This method is particularly useful for sniffs which examine the contents of text strings, where the content matching might result in false positives/false negatives if the text were to be examined line by line.

Parameters
$phpcsFile : File

The file where this token was found.

$stackPtr : int

Pointer to the first text string token of a - potentially multi-line - text string or to a Nowdoc/Heredoc opener.

$stripQuotes : bool = true

Optional. Whether to strip text delimiter quotes off the resulting text string. Defaults to true.

Tags
since
1.0.0
throws
RuntimeException

If the specified position is not a valid text string token.

throws
RuntimeException

If the specified token is not the first token in a text string.

Return values
string

The complete text string.

stripQuotes()

Strip text delimiter quotes from an arbitrary string.

public static stripQuotes(string $string) : string

Intended for use with the "contents" of a T_CONSTANT_ENCAPSED_STRING / T_DOUBLE_QUOTED_STRING.

  • Prevents stripping mis-matched quotes.
  • Prevents stripping quotes from the textual content of the string.
Parameters
$string : string

The raw string.

Tags
since
1.0.0
Return values
string

String without quotes around it.

Search results