Chris@0: getTokens(); Chris@0: if ($tokens[$stackPtr]['content'] !== '"#options"' && $tokens[$stackPtr]['content'] !== "'#options'") { Chris@0: return; Chris@0: } Chris@0: Chris@0: // Look for an opening array pattern that starts to define #options Chris@0: // values. Chris@0: $statementEnd = $phpcsFile->findNext(T_SEMICOLON, ($stackPtr + 1)); Chris@0: $arrayString = $phpcsFile->getTokensAsString(($stackPtr + 1), ($statementEnd - $stackPtr)); Chris@0: // Cut out all the white space. Chris@0: $arrayString = preg_replace('/\s+/', '', $arrayString); Chris@0: Chris@0: if (strpos($arrayString, '=>array(') !== 0 && strpos($arrayString, ']=array(') !== 0) { Chris@0: return; Chris@0: } Chris@0: Chris@0: // We only search within the #options array. Chris@0: $arrayToken = $phpcsFile->findNext(T_ARRAY, ($stackPtr + 1)); Chris@0: $statementEnd = $tokens[$arrayToken]['parenthesis_closer']; Chris@0: Chris@0: // Go through the array by examining stuff after "=>". Chris@0: $arrow = $phpcsFile->findNext(T_DOUBLE_ARROW, ($stackPtr + 1), $statementEnd, false, null, true); Chris@0: while ($arrow !== false) { Chris@0: $arrayValue = $phpcsFile->findNext(T_WHITESPACE, ($arrow + 1), $statementEnd, true); Chris@0: // We are only interested in string literals that are not numbers Chris@0: // and more than 3 characters long. Chris@0: if ($tokens[$arrayValue]['code'] === T_CONSTANT_ENCAPSED_STRING Chris@0: && is_numeric(substr($tokens[$arrayValue]['content'], 1, -1)) === false Chris@0: && strlen($tokens[$arrayValue]['content']) > 5 Chris@0: ) { Chris@0: // We need to make sure that the string is the one and only part Chris@0: // of the array value. Chris@0: $afterValue = $phpcsFile->findNext(T_WHITESPACE, ($arrayValue + 1), $statementEnd, true); Chris@0: if ($tokens[$afterValue]['code'] === T_COMMA || $tokens[$afterValue]['code'] === T_CLOSE_PARENTHESIS) { Chris@0: $warning = '#options values usually have to run through t() for translation'; Chris@0: $phpcsFile->addWarning($warning, $arrayValue, 'TforValue'); Chris@0: } Chris@0: } Chris@0: Chris@0: $arrow = $phpcsFile->findNext(T_DOUBLE_ARROW, ($arrow + 1), $statementEnd, false, null, true); Chris@0: } Chris@0: Chris@0: }//end process() Chris@0: Chris@0: Chris@0: }//end class