|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * This sniff prohibits the use of single line multi line comments |
| 4 | + * |
| 5 | + * PHP version 5 |
| 6 | + * |
| 7 | + * @category PHP |
| 8 | + * @package PHP_CodeSniffer |
| 9 | + * @author Ryan Matthews <rmatthews@barracuda.com> |
| 10 | + * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence |
| 11 | + * @version 1.0.00 |
| 12 | + * @link http://pear.php.net/package/PHP_CodeSniffer |
| 13 | + */ |
| 14 | + |
| 15 | +/** |
| 16 | + * This sniff prohibits the use of Perl style hash comments. |
| 17 | + * |
| 18 | + * An example of a hash comment is: |
| 19 | + * |
| 20 | + * <code> |
| 21 | + * /* This is a single line multi line comment, which is prohibited. */ |
| 22 | +/* $hello = 'hello'; |
| 23 | + * </code> |
| 24 | + * |
| 25 | + * @category PHP |
| 26 | + * @package PHP_CodeSniffer |
| 27 | + * @author Ryan Matthews <rmatthews@barracuda.com> |
| 28 | + * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence |
| 29 | + * @version Release: 1.0.00 |
| 30 | + * @link http://pear.php.net/package/PHP_CodeSniffer |
| 31 | + */ |
| 32 | +class Barracuda_Sniffs_Commenting_DisallowSingleLineMultiCommentsSniff implements PHP_CodeSniffer_Sniff |
| 33 | +{ |
| 34 | + |
| 35 | + |
| 36 | + /** |
| 37 | + * Returns the token types that this sniff is interested in. |
| 38 | + * |
| 39 | + * @return array(int) |
| 40 | + */ |
| 41 | + public function register() |
| 42 | + { |
| 43 | + return array(T_COMMENT); |
| 44 | + |
| 45 | + }// end register() |
| 46 | + |
| 47 | + |
| 48 | + /** |
| 49 | + * Processes the tokens that this sniff is interested in. |
| 50 | + * |
| 51 | + * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found. |
| 52 | + * @param int $stackPtr The position in the stack where |
| 53 | + * the token was found. |
| 54 | + * |
| 55 | + * @return void |
| 56 | + */ |
| 57 | + public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
| 58 | + { |
| 59 | + $tokens = $phpcsFile->getTokens(); |
| 60 | + if (preg_match('/\/\*[^\n]*\*\//', $tokens[$stackPtr]['content'])) |
| 61 | + { |
| 62 | + $error = 'Multi line comments are prohibited on single lines; found %s'; |
| 63 | + $data = array(trim($tokens[$stackPtr]['content'])); |
| 64 | + $phpcsFile->addError($error, $stackPtr, 'Found', $data); |
| 65 | + } |
| 66 | + |
| 67 | + }// end process() |
| 68 | +} |
| 69 | +// end class |
| 70 | + |
0 commit comments