diff --git a/package.xml b/package.xml index 105705a572..43a47c10d6 100644 --- a/package.xml +++ b/package.xml @@ -273,6 +273,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> + @@ -368,6 +369,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> + @@ -568,6 +570,8 @@ http://pear.php.net/dtd/package-2.0.xsd"> + + diff --git a/src/Standards/Generic/Docs/PHP/DiscourageGotoStandard.xml b/src/Standards/Generic/Docs/PHP/DiscourageGotoStandard.xml new file mode 100644 index 0000000000..83bceef40d --- /dev/null +++ b/src/Standards/Generic/Docs/PHP/DiscourageGotoStandard.xml @@ -0,0 +1,7 @@ + + + + + diff --git a/src/Standards/Generic/Sniffs/PHP/DiscourageGotoSniff.php b/src/Standards/Generic/Sniffs/PHP/DiscourageGotoSniff.php new file mode 100644 index 0000000000..dcaa3ef0c6 --- /dev/null +++ b/src/Standards/Generic/Sniffs/PHP/DiscourageGotoSniff.php @@ -0,0 +1,50 @@ + + * @copyright 2006-2017 Squiz Pty Ltd (ABN 77 084 670 600) + * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence + */ + +namespace PHP_CodeSniffer\Standards\Generic\Sniffs\PHP; + +use PHP_CodeSniffer\Sniffs\Sniff; +use PHP_CodeSniffer\Files\File; + +class DiscourageGotoSniff implements Sniff +{ + + + /** + * Returns an array of tokens this test wants to listen for. + * + * @return array + */ + public function register() + { + return array( + T_GOTO, + T_GOTO_LABEL, + ); + + }//end register() + + + /** + * Processes this sniff, 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) + { + $phpcsFile->addWarning('Using the "goto" language construct is discouraged', $stackPtr, 'Found'); + + }//end process() + + +}//end class diff --git a/src/Standards/Generic/Tests/PHP/DiscourageGotoUnitTest.inc b/src/Standards/Generic/Tests/PHP/DiscourageGotoUnitTest.inc new file mode 100644 index 0000000000..f564215b05 --- /dev/null +++ b/src/Standards/Generic/Tests/PHP/DiscourageGotoUnitTest.inc @@ -0,0 +1,18 @@ + + * @copyright 2006-2017 Squiz Pty Ltd (ABN 77 084 670 600) + * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence + */ + +namespace PHP_CodeSniffer\Standards\Generic\Tests\PHP; + +use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; + +class DiscourageGotoUnitTest 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(); + + }//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( + 3 => 1, + 6 => 1, + 11 => 1, + 16 => 1, + ); + + }//end getWarningList() + + +}//end class