Created
October 5, 2012 11:55
-
-
Save digitalkaoz/3839401 to your computer and use it in GitHub Desktop.
else if vs elseif sniff
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Unity_Sniffs_Formatting_ElseIfSniff. | |
* | |
* Sniff: | |
* - else if instead of elseif | |
*/ | |
class Unity_Sniffs_Formatting_ElseIfSniff implements PHP_CodeSniffer_Sniff | |
{ | |
/** | |
* Returns an array of tokens this test wants to listen for. | |
* | |
* @return array | |
*/ | |
public function register() | |
{ | |
return array(T_ELSE); | |
} //end register() | |
/** | |
* Processes return statement sniff | |
* | |
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned. | |
* @param int $stackPtr The position of the current token in the | |
* stack passed in $tokens. | |
*/ | |
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) | |
{ | |
$nextIf = $phpcsFile->findNext(T_IF, $stackPtr); | |
//+2 da noch ein leerzeichen dazwischen ist | |
if ($stackPtr+2 == $nextIf) { | |
$phpcsFile->addError('"else if" is disallowed, use "elseif" instead', $stackPtr, 'ElseIf'); | |
} | |
} //end process() | |
} //end class |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment