Last active
December 4, 2016 04:51
-
-
Save bmax/f29fa5063f878f168b8eb47d76a305fd to your computer and use it in GitHub Desktop.
This file contains 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 | |
class Behance_Sniffs_Gotchas_PHPUnitExpectsSniff implements PHP_CodeSniffer_Sniff { | |
public function register() { | |
return [ T_STRING ]; | |
} // register | |
/** | |
* Processes this test, when one of its tokens is encountered. | |
* | |
* @param PHP_CodeSniffer_File $phpcsFile All the tokens found in the document. | |
* @param int $stackPtr The position of the current token in the | |
* stack passed in $tokens. | |
*/ | |
public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { | |
$tokens = $phpcsFile->getTokens(); | |
$string_found = $tokens[ $stackPtr ]; | |
$previous_variable = $tokens[ $stackPtr - 2 ]; | |
if ( $string_found['content'] !== "expects") { | |
return; | |
} | |
if ( $tokens[ $stackPtr - 1 ]['code'] !== T_OBJECT_OPERATOR ) { | |
return; | |
} | |
if ( $previous_variable['code'] !== T_VARIABLE ) { | |
$error = 'Using expects method must be next method called on variable'; | |
$phpcsFile->addError( $error, $stackPtr ); | |
} | |
if ( $previous_variable['line'] !== $string_found['line']) { | |
$error = 'Using expects method must be on same line as variable'; | |
$phpcsFile->addError( $error, $stackPtr ); | |
} | |
} // process | |
} // Behance_Sniffs_Gotchas_DefaultLoggerSniff |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment