function FunctionTSniff::checkConcatString
Checks if a string can be concatenated with a translatable string.
Parameters
string $string The string that is concatenated to a t() call.:
Return value
bool TRUE if the string is allowed to be concatenated with a translatable string, FALSE if not.
1 call to FunctionTSniff::checkConcatString()
- FunctionTSniff::processFunctionCall in vendor/
drupal/ coder/ coder_sniffer/ Drupal/ Sniffs/ Semantics/ FunctionTSniff.php - Processes this function call.
File
-
vendor/
drupal/ coder/ coder_sniffer/ Drupal/ Sniffs/ Semantics/ FunctionTSniff.php, line 148
Class
- FunctionTSniff
- Check the usage of the t() function to not escape translatable strings with back slashes. Also checks that the first argument does not use string concatenation.
Namespace
Drupal\Sniffs\SemanticsCode
protected function checkConcatString($string) {
// Remove outer quotes, spaces and HTML tags from the original string.
$string = trim($string, '"\'');
$string = trim(strip_tags($string));
if ($string === '') {
return true;
}
$allowedItems = [
'(',
')',
'[',
']',
'-',
'<',
'>',
'«',
'»',
'\\n',
];
foreach ($allowedItems as $item) {
if ($item === $string) {
return true;
}
}
return false;
}