diff --git a/BigBite/Docs/PHP/HeredocStandard.xml b/BigBite/Docs/PHP/HeredocStandard.xml new file mode 100644 index 0000000..2f84ca6 --- /dev/null +++ b/BigBite/Docs/PHP/HeredocStandard.xml @@ -0,0 +1,29 @@ + + + + + + + + + + <<; +$text2 = <<; + ]]> + + + diff --git a/BigBite/Sniffs/PHP/HeredocSniff.php b/BigBite/Sniffs/PHP/HeredocSniff.php new file mode 100644 index 0000000..1ae1d68 --- /dev/null +++ b/BigBite/Sniffs/PHP/HeredocSniff.php @@ -0,0 +1,42 @@ + + */ + public function register() { + return array( T_START_HEREDOC ); + } + + /** + * Processes this test when one of its tokens is encountered. + * + * @param \PHP_CodeSniffer\Files\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( File $phpcsFile, $stackPtr ) { + $error = 'Use of heredoc syntax ("<<<") is not allowed; use standard strings or inline HTML instead'; + $phpcsFile->addError( $error, $stackPtr, 'NotAllowed' ); + } +} diff --git a/BigBite/Tests/PHP/HeredocUnitTest.1.inc b/BigBite/Tests/PHP/HeredocUnitTest.1.inc new file mode 100644 index 0000000..4e92adb --- /dev/null +++ b/BigBite/Tests/PHP/HeredocUnitTest.1.inc @@ -0,0 +1,7 @@ + + */ + public function getErrorList( $testFile = '' ) { + switch ( $testFile ) { + case 'HeredocUnitTest.1.inc': + return array( 2 => 1 ); + default: + return array(); + } + } + + /** + * 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(); + } +}