Chris@0: getFilename(), -7)); Chris@0: // Only check in *.install files. Chris@0: if ($fileExtension !== 'install') { Chris@0: return; Chris@0: } Chris@0: Chris@0: $fileName = substr(basename($phpcsFile->getFilename()), 0, -8); Chris@0: $tokens = $phpcsFile->getTokens(); Chris@0: if ($tokens[$stackPtr]['content'] !== ($fileName.'_install') Chris@0: && $tokens[$stackPtr]['content'] !== ($fileName.'_requirements') Chris@0: ) { Chris@0: return; Chris@0: } Chris@0: Chris@0: // This check only applies to Drupal 7, not Drupal 8. Chris@17: if (Project::getCoreVersion($phpcsFile) !== '7.x') { Chris@0: return; Chris@0: } Chris@0: Chris@0: // Search in the function body for t() calls. Chris@0: $string = $phpcsFile->findNext( Chris@0: T_STRING, Chris@0: $tokens[$functionPtr]['scope_opener'], Chris@0: $tokens[$functionPtr]['scope_closer'] Chris@0: ); Chris@0: while ($string !== false) { Chris@0: if ($tokens[$string]['content'] === 't' || $tokens[$string]['content'] === 'st') { Chris@0: $opener = $phpcsFile->findNext( Chris@17: Tokens::$emptyTokens, Chris@0: ($string + 1), Chris@0: null, Chris@0: true Chris@0: ); Chris@0: if ($opener !== false Chris@0: && $tokens[$opener]['code'] === T_OPEN_PARENTHESIS Chris@0: ) { Chris@0: $error = 'Do not use t() or st() in installation phase hooks, use $t = get_t() to retrieve the appropriate localization function name'; Chris@0: $phpcsFile->addError($error, $string, 'TranslationFound'); Chris@0: } Chris@0: } Chris@0: Chris@0: $string = $phpcsFile->findNext( Chris@0: T_STRING, Chris@0: ($string + 1), Chris@0: $tokens[$functionPtr]['scope_closer'] Chris@0: ); Chris@0: }//end while Chris@0: Chris@0: }//end processFunction() Chris@0: Chris@0: Chris@0: }//end class