Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If you run phpcs with the <code>-vv</code> command line argument, you can see a list of tokens that the PHP file is broken into. For a line like <code>Firebug::error();</code> you get:</p> <pre><code>Process token 1 on line 2 [lvl:0;]: T_STRING =&gt; Firebug Process token 2 on line 2 [lvl:0;]: T_DOUBLE_COLON =&gt; :: Process token 3 on line 2 [lvl:0;]: T_STRING =&gt; error Process token 4 on line 2 [lvl:0;]: T_OPEN_PARENTHESIS =&gt; ( Process token 5 on line 2 [lvl:0;]: T_CLOSE_PARENTHESIS =&gt; ) Process token 6 on line 2 [lvl:0;]: T_SEMICOLON =&gt; ; </code></pre> <p>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:</p> <pre><code>if ($tokens[$stackPtr]['content'] === 'Firebug' &amp;&amp; $tokens[($stackPtr + 1)]['code'] === T_DOUBLE_COLON ) { // This is a static call to a Firebug class method. $methodName = $tokens[($stackPtr + 2)]['content']; /* your error code here */ } </code></pre> <p>Or, if you think people are going to put spaces between the double colons, like <code>Firebug :: error()</code> then you can do something like this:</p> <pre><code>if ($tokens[$stackPtr]['content'] === 'Firebug') { // Find the next non-whitespace token. $colon = $phpcsFile-&gt;findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr + 1), null, true); if ($tokens[$colon]['code'] === T_DOUBLE_COLON) { // This is a static call to a Firebug class method. $methodName = $phpcsFile-&gt;findNext(T_STRING, ($colon + 1)); /* your error code here */ } } </code></pre> <p>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.</p> <p>Hope that helps.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload