You are here

protected function FunctionTSniff::checkConcatString in Coder 8.2

Same name and namespace in other branches
  1. 8.3 coder_sniffer/Drupal/Sniffs/Semantics/FunctionTSniff.php \Drupal\Sniffs\Semantics\FunctionTSniff::checkConcatString()
  2. 8.3.x coder_sniffer/Drupal/Sniffs/Semantics/FunctionTSniff.php \Drupal\Sniffs\Semantics\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 coder_sniffer/Drupal/Sniffs/Semantics/FunctionTSniff.php
Processes this function call.

File

coder_sniffer/Drupal/Sniffs/Semantics/FunctionTSniff.php, line 149

Class

FunctionTSniff
Check the usage of the t() function to not escape translateable strings with back slashes. Also checks that the first argument does not use string concatenation.

Namespace

Drupal\Sniffs\Semantics

Code

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;
  }
  $allowed_items = array(
    '(',
    ')',
    '[',
    ']',
    '-',
    '<',
    '>',
    '«',
    '»',
    '\\n',
  );
  foreach ($allowed_items as $item) {
    if ($item === $string) {
      return true;
    }
  }
  return false;
}