If you run phpcs with the -vv
command line argument, you can see a list of tokens that the PHP file is broken into. For a line like Firebug::error();
you get:
Process token 1 on line 2 [lvl:0;]: T_STRING => Firebug
Process token 2 on line 2 [lvl:0;]: T_DOUBLE_COLON => ::
Process token 3 on line 2 [lvl:0;]: T_STRING => error
Process token 4 on line 2 [lvl:0;]: T_OPEN_PARENTHESIS => (
Process token 5 on line 2 [lvl:0;]: T_CLOSE_PARENTHESIS => )
Process token 6 on line 2 [lvl:0;]: T_SEMICOLON => ;
You don't show your whole sniff, but I assume you are looking for the T_STRING token. In this case, once you've determined that $stackPtr is pointing to the "Firebug" sting, just confirm it is a static call and then grab the next string token:
if ($tokens[$stackPtr]['content'] === 'Firebug'
&& $tokens[($stackPtr + 1)]['code'] === T_DOUBLE_COLON
) {
$methodName = $tokens[($stackPtr + 2)]['content'];
}
Or, if you think people are going to put spaces between the double colons, like Firebug :: error()
then you can do something like this:
if ($tokens[$stackPtr]['content'] === 'Firebug') {
$colon = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr + 1), null, true);
if ($tokens[$colon]['code'] === T_DOUBLE_COLON) {
$methodName = $phpcsFile->findNext(T_STRING, ($colon + 1));
}
}
If you want to go a step further, you can look for the T_OPEN_PARENTHESIS and T_CLOSE_PARENTHESIS tokens as well, to confirm it is a function call, but it depends on the class you are using.
Hope that helps.