Chris@0: getFilename(), -6)); Chris@0: // Only check in *.module files. Chris@0: if ($fileExtension !== 'module') { Chris@0: return; Chris@0: } Chris@0: Chris@0: // This check only applies to Drupal 7, not Drupal 6. Chris@17: if (Project::getCoreVersion($phpcsFile) !== '7.x') { Chris@0: return; Chris@0: } Chris@0: Chris@0: $fileName = substr(basename($phpcsFile->getFilename()), 0, -7); Chris@0: $tokens = $phpcsFile->getTokens(); Chris@0: if ($tokens[$stackPtr]['content'] !== ($fileName.'_init') && $tokens[$stackPtr]['content'] !== ($fileName.'_page_build')) { Chris@0: return; Chris@0: } Chris@0: Chris@0: // Search in the function body for drupal_add_css() 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'] === 'drupal_add_css' || $tokens[$string]['content'] === 'drupal_add_js') { 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: if ($tokens[$stackPtr]['content'] === ($fileName.'_init')) { Chris@0: $warning = 'Do not use %s() in hook_init(), use #attached for CSS and JS in your page/form callback or in hook_page_build() instead'; Chris@0: $phpcsFile->addWarning($warning, $string, 'AddFunctionFound', array($tokens[$string]['content'])); Chris@0: } else { Chris@0: $warning = 'Do not use %s() in hook_page_build(), use #attached for CSS and JS on the $page render array instead'; Chris@0: $phpcsFile->addWarning($warning, $string, 'AddFunctionFoundPageBuild', array($tokens[$string]['content'])); Chris@0: } 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