diff --git a/WordPress-Core/ruleset.xml b/WordPress-Core/ruleset.xml index 35db8e6dbd..3c77544afd 100644 --- a/WordPress-Core/ruleset.xml +++ b/WordPress-Core/ruleset.xml @@ -17,6 +17,7 @@ + diff --git a/WordPress/Sniffs/PHP/DisallowAlternativeOpenTagSniff.php b/WordPress/Sniffs/PHP/DisallowAlternativeOpenTagSniff.php new file mode 100644 index 0000000000..f8b46c8a36 --- /dev/null +++ b/WordPress/Sniffs/PHP/DisallowAlternativeOpenTagSniff.php @@ -0,0 +1,64 @@ + + */ +class WordPress_Sniffs_PHP_DisallowAlternativeOpenTagSniff implements PHP_CodeSniffer_Sniff { + + /** + * Returns an array of tokens this test wants to listen for. + * + * @return array + */ + public function register() { + return array( + T_OPEN_TAG, + T_OPEN_TAG_WITH_ECHO, + ); + + } //end register() + + + /** + * Processes this test, when one of its tokens is encountered. + * + * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. + * @param int $stackPtr The position of the current token + * in the stack passed in $tokens. + * + * @return void + */ + public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { + $tokens = $phpcsFile->getTokens(); + $openTag = $tokens[ $stackPtr ]; + + if ( '<%' === $openTag['content'] ) { + $error = 'ASP style opening tag used; expected "addError( $error, $stackPtr, 'ASPOpenTag', $data ); + } + + if ( ' + diff --git a/WordPress/Tests/PHP/DisallowAlternativeOpenTagUnitTest.php b/WordPress/Tests/PHP/DisallowAlternativeOpenTagUnitTest.php new file mode 100644 index 0000000000..88338b9b43 --- /dev/null +++ b/WordPress/Tests/PHP/DisallowAlternativeOpenTagUnitTest.php @@ -0,0 +1,45 @@ + + */ +class WordPress_Tests_PHP_DisallowAlternativeOpenTagUnitTest extends AbstractSniffUnitTest { + + /** + * Returns the lines where errors should occur. + * + * The key of the array should represent the line number and the value + * should represent the number of errors that should occur on that line. + * + * @return array + */ + public function getErrorList() { + return array( + 4 => 1, + 5 => 1, + 6 => 1, + ); + + } //end getErrorList() + + + /** + * Returns the lines where warnings should occur. + * + * The key of the array should represent the line number and the value + * should represent the number of warnings that should occur on that line. + * + * @return array + */ + public function getWarningList() { + return array(); + } //end getWarningList() + + +} //end class