Mercurial > hg > isophonics-drupal-site
annotate vendor/drupal/coder/coder_sniffer/DrupalPractice/Sniffs/Commenting/ExpectedExceptionSniff.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children | 129ea1e6d783 |
rev | line source |
---|---|
Chris@0 | 1 <?php |
Chris@0 | 2 /** |
Chris@0 | 3 * DrupalPractice_Sniffs_Commenting_ExpectedExceptionSniff. |
Chris@0 | 4 * |
Chris@0 | 5 * @category PHP |
Chris@0 | 6 * @package PHP_CodeSniffer |
Chris@0 | 7 * @link http://pear.php.net/package/PHP_CodeSniffer |
Chris@0 | 8 */ |
Chris@0 | 9 |
Chris@0 | 10 /** |
Chris@0 | 11 * Checks that the PHPunit @expectedExcpetion tags are not used. |
Chris@0 | 12 * |
Chris@0 | 13 * See https://thephp.cc/news/2016/02/questioning-phpunit-best-practices . |
Chris@0 | 14 * |
Chris@0 | 15 * @category PHP |
Chris@0 | 16 * @package PHP_CodeSniffer |
Chris@0 | 17 * @link http://pear.php.net/package/PHP_CodeSniffer |
Chris@0 | 18 */ |
Chris@0 | 19 class DrupalPractice_Sniffs_Commenting_ExpectedExceptionSniff implements PHP_CodeSniffer_Sniff |
Chris@0 | 20 { |
Chris@0 | 21 |
Chris@0 | 22 |
Chris@0 | 23 /** |
Chris@0 | 24 * Returns an array of tokens this test wants to listen for. |
Chris@0 | 25 * |
Chris@0 | 26 * @return array |
Chris@0 | 27 */ |
Chris@0 | 28 public function register() |
Chris@0 | 29 { |
Chris@0 | 30 return array(T_DOC_COMMENT_TAG); |
Chris@0 | 31 |
Chris@0 | 32 }//end register() |
Chris@0 | 33 |
Chris@0 | 34 |
Chris@0 | 35 /** |
Chris@0 | 36 * Processes this test, when one of its tokens is encountered. |
Chris@0 | 37 * |
Chris@0 | 38 * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. |
Chris@0 | 39 * @param int $stackPtr The position of the current token |
Chris@0 | 40 * in the stack passed in $tokens. |
Chris@0 | 41 * |
Chris@0 | 42 * @return void |
Chris@0 | 43 */ |
Chris@0 | 44 public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
Chris@0 | 45 { |
Chris@0 | 46 $tokens = $phpcsFile->getTokens(); |
Chris@0 | 47 |
Chris@0 | 48 $content = $tokens[$stackPtr]['content']; |
Chris@0 | 49 if ($content === '@expectedException' || $content === '@expectedExceptionCode' |
Chris@0 | 50 || $content === '@expectedExceptionMessage' |
Chris@0 | 51 || $content === '@expectedExceptionMessageRegExp' |
Chris@0 | 52 ) { |
Chris@0 | 53 $warning = '%s tags should not be used, use $§this->setExpectedException() or $this->expectException() instead'; |
Chris@0 | 54 $phpcsFile->addWarning($warning, $stackPtr, 'TagFound', [$content]); |
Chris@0 | 55 } |
Chris@0 | 56 |
Chris@0 | 57 }//end process() |
Chris@0 | 58 |
Chris@0 | 59 |
Chris@0 | 60 }//end class |