Chris@0: getTokens(); Chris@0: Chris@0: // We assume that the sequence '#default_value' => variable_get(...) Chris@0: // indicates a variable that the module owns. Chris@17: $arrow = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true); Chris@0: if ($arrow === false || $tokens[$arrow]['code'] !== T_DOUBLE_ARROW) { Chris@0: return; Chris@0: } Chris@0: Chris@17: $arrayKey = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($arrow - 1), null, true); Chris@0: if ($arrayKey === false Chris@0: || $tokens[$arrayKey]['code'] !== T_CONSTANT_ENCAPSED_STRING Chris@0: || substr($tokens[$arrayKey]['content'], 1, -1) !== '#default_value' Chris@0: ) { Chris@0: return; Chris@0: } Chris@0: Chris@0: $argument = $this->getArgument(1); Chris@0: Chris@0: // Variable name is not a literal string, so we return early. Chris@0: if ($argument === false || $tokens[$argument['start']]['code'] !== T_CONSTANT_ENCAPSED_STRING) { Chris@0: return; Chris@0: } Chris@0: Chris@17: $moduleName = Project::getName($phpcsFile); Chris@0: if ($moduleName === false) { Chris@0: return; Chris@0: } Chris@0: Chris@0: $variableName = substr($tokens[$argument['start']]['content'], 1, -1); Chris@0: if (strpos($variableName, $moduleName) !== 0) { Chris@0: $warning = 'All variables defined by your module must be prefixed with your module\'s name to avoid name collisions with others. Expected start with "%s" but found "%s"'; Chris@0: $data = array( Chris@0: $moduleName, Chris@0: $variableName, Chris@0: ); Chris@0: $phpcsFile->addWarning($warning, $argument['start'], 'VariableName', $data); Chris@0: } Chris@0: Chris@0: }//end processFunctionCall() Chris@0: Chris@0: Chris@0: }//end class