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: $fileName = substr(basename($phpcsFile->getFilename()), 0, -7); Chris@0: $tokens = $phpcsFile->getTokens(); Chris@0: if ($tokens[$stackPtr]['content'] !== ($fileName.'_menu')) { Chris@0: return; Chris@0: } Chris@0: Chris@0: // Search for 'access callabck' => TRUE in the function body. Chris@0: $string = $phpcsFile->findNext( Chris@0: T_CONSTANT_ENCAPSED_STRING, Chris@0: $tokens[$functionPtr]['scope_opener'], Chris@0: $tokens[$functionPtr]['scope_closer'] Chris@0: ); Chris@0: while ($string !== false) { Chris@0: if (substr($tokens[$string]['content'], 1, -1) === 'access callback') { Chris@0: $array_operator = $phpcsFile->findNext( Chris@17: Tokens::$emptyTokens, Chris@0: ($string + 1), Chris@0: null, Chris@0: true Chris@0: ); Chris@0: if ($array_operator !== false Chris@0: && $tokens[$array_operator]['code'] === T_DOUBLE_ARROW Chris@0: ) { Chris@0: $callback = $phpcsFile->findNext( Chris@17: Tokens::$emptyTokens, Chris@0: ($array_operator + 1), Chris@0: null, Chris@0: true Chris@0: ); Chris@0: if ($callback !== false && $tokens[$callback]['code'] === T_TRUE) { Chris@0: // Check if there is a comment before the line that might Chris@0: // explain stuff. Chris@0: $commentBefore = $phpcsFile->findPrevious( Chris@0: T_WHITESPACE, Chris@0: ($string - 1), Chris@0: $tokens[$functionPtr]['scope_opener'], Chris@0: true Chris@0: ); Chris@17: if ($commentBefore !== false && in_array($tokens[$commentBefore]['code'], Tokens::$commentTokens) === false) { Chris@0: $warning = 'Open page callback found, please add a comment before the line why there is no access restriction'; Chris@0: $phpcsFile->addWarning($warning, $callback, 'OpenCallback'); Chris@0: } Chris@0: } Chris@0: }//end if Chris@0: }//end if Chris@0: Chris@0: $string = $phpcsFile->findNext( Chris@0: T_CONSTANT_ENCAPSED_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