PHP_CodeSniffer
[ class tree: PHP_CodeSniffer ] [ index: PHP_CodeSniffer ] [ all elements ]

Source for file FixmeSniff.php

Documentation is available at FixmeSniff.php

  1. <?php
  2. /**
  3.  * Warns about FIXME comments.
  4.  *
  5.  * @author    Greg Sherwood <gsherwood@squiz.net>
  6.  * @author    Sam Graham <php-codesniffer@illusori.co.uk>
  7.  * @copyright 2006-2015 Squiz Pty Ltd (ABN 77 084 670 600)
  8.  * @license   https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
  9.  */
  10.  
  11. namespace PHP_CodeSniffer\Standards\Generic\Sniffs\Commenting;
  12.  
  13. use PHP_CodeSniffer\Sniffs\Sniff;
  14. use PHP_CodeSniffer\Files\File;
  15. use PHP_CodeSniffer\Util\Tokens;
  16.  
  17. class FixmeSniff implements Sniff
  18. {
  19.  
  20.     /**
  21.      * A list of tokenizers this sniff supports.
  22.      *
  23.      * @var array 
  24.      */
  25.     public $supportedTokenizers = array(
  26.                                    'PHP',
  27.                                    'JS',
  28.                                   );
  29.  
  30.  
  31.     /**
  32.      * Returns an array of tokens this test wants to listen for.
  33.      *
  34.      * @return array 
  35.      */
  36.     public function register()
  37.     {
  38.         return Tokens::$commentTokens;
  39.  
  40.     }//end register()
  41.  
  42.  
  43.     /**
  44.      * Processes this sniff, when one of its tokens is encountered.
  45.      *
  46.      * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
  47.      * @param int                         $stackPtr  The position of the current token
  48.      *                                                in the stack passed in $tokens.
  49.      *
  50.      * @return void 
  51.      */
  52.     public function process(File $phpcsFile$stackPtr)
  53.     {
  54.         $tokens $phpcsFile->getTokens();
  55.  
  56.         $content $tokens[$stackPtr]['content'];
  57.         $matches = array();
  58.         preg_match('/(?:\A|[^\p{L}]+)fixme([^\p{L}]+(.*)|\Z)/ui'$content$matches);
  59.         if (empty($matches=== false{
  60.             // Clear whitespace and some common characters not required at
  61.             // the end of a fixme message to make the error more informative.
  62.             $type         'CommentFound';
  63.             $fixmeMessage trim($matches[1]);
  64.             $fixmeMessage trim($fixmeMessage'-:[](). ');
  65.             $error        'Comment refers to a FIXME task';
  66.             $data         = array($fixmeMessage);
  67.             if ($fixmeMessage !== ''{
  68.                 $type   'TaskFound';
  69.                 $error .= ' "%s"';
  70.             }
  71.  
  72.             $phpcsFile->addError($error$stackPtr$type$data);
  73.         }
  74.  
  75.     }//end process()
  76.  
  77.  
  78. }//end class

Documentation generated on Mon, 11 Mar 2019 15:27:29 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.