Subversion Repositories Applications.framework

Rev

Rev 5 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
5 aurelien 1
<?php
2
/**
3
 * Generic_Sniffs_Commenting_TodoSniff.
4
 *
5
 * PHP version 5
6
 *
7
 * @category  PHP
8
 * @package   PHP_CodeSniffer
9
 * @author    Greg Sherwood <gsherwood@squiz.net>
10
 * @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
11
 * @license   http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
34 aurelien 12
 * @version   CVS: $Id: TodoSniff.php 34 2009-04-09 07:34:39Z aurelien $
5 aurelien 13
 * @link      http://pear.php.net/package/PHP_CodeSniffer
14
 */
15
 
16
/**
17
 * Generic_Sniffs_Commenting_TodoSniff.
18
 *
19
 * Warns about TODO comments.
20
 *
21
 * @category  PHP
22
 * @package   PHP_CodeSniffer
23
 * @author    Greg Sherwood <gsherwood@squiz.net>
24
 * @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
25
 * @license   http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
26
 * @version   Release: 1.2.0RC1
27
 * @link      http://pear.php.net/package/PHP_CodeSniffer
28
 */
29
class Generic_Sniffs_Commenting_TodoSniff implements PHP_CodeSniffer_Sniff
30
{
31
 
32
    /**
33
     * A list of tokenizers this sniff supports.
34
     *
35
     * @var array
36
     */
37
    public $supportedTokenizers = array(
38
                                   'PHP',
39
                                   'JS',
40
                                  );
41
 
42
 
43
    /**
44
     * Returns an array of tokens this test wants to listen for.
45
     *
46
     * @return array
47
     */
48
    public function register()
49
    {
50
        return PHP_CodeSniffer_Tokens::$commentTokens;
51
 
52
    }//end register()
53
 
54
 
55
    /**
56
     * Processes this sniff, when one of its tokens is encountered.
57
     *
58
     * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
59
     * @param int                  $stackPtr  The position of the current token
60
     *                                        in the stack passed in $tokens.
61
     *
62
     * @return void
63
     */
64
    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
65
    {
66
        $tokens = $phpcsFile->getTokens();
67
 
68
        $content = $tokens[$stackPtr]['content'];
69
        $matches = Array();
70
        if (preg_match('|[^a-z]+todo[^a-z]+(.*)|i', $content, $matches) !== 0) {
71
            // Clear whitespace and some common characters not required at
72
            // the end of a to-do message to make the warning more informative.
73
            $todoMessage = trim($matches[1]);
74
            $todoMessage = trim($todoMessage, '[]().');
75
            $error       = 'Comment refers to a TODO task';
76
            if ($todoMessage !== '') {
77
                $error .= " \"$todoMessage\"";
78
            }
79
 
80
            $phpcsFile->addWarning($error, $stackPtr);
81
        }
82
 
83
    }//end process()
84
 
85
 
86
}//end class
87
 
88
?>