| 
12 | 12 | 
 
  | 
13 | 13 | use PHP_CodeSniffer\Files\File;  | 
14 | 14 | use PHP_CodeSniffer\Sniffs\Sniff;  | 
15 |  | -use PHP_CodeSniffer\Util\Tokens;  | 
16 | 15 | 
 
  | 
17 | 16 | class FixmeSniff implements Sniff  | 
18 | 17 | {  | 
@@ -56,27 +55,40 @@ public function register()  | 
56 | 55 |      */  | 
57 | 56 |     public function process(File $phpcsFile, $stackPtr)  | 
58 | 57 |     {  | 
59 |  | -        $tokens = $phpcsFile->getTokens();  | 
60 |  | - | 
 | 58 | +        $tokens  = $phpcsFile->getTokens();  | 
61 | 59 |         $content = $tokens[$stackPtr]['content'];  | 
62 | 60 |         $matches = [];  | 
63 |  | -        preg_match('/(?:\A|[^\p{L}]+)fixme([^\p{L}]+(.*)|\Z)/ui', $content, $matches);  | 
64 |  | -        if (empty($matches) === false) {  | 
65 |  | -            // Clear whitespace and some common characters not required at  | 
66 |  | -            // the end of a fixme message to make the error more informative.  | 
67 |  | -            $type         = 'CommentFound';  | 
68 |  | -            $fixmeMessage = trim($matches[1]);  | 
69 |  | -            $fixmeMessage = trim($fixmeMessage, '-:[](). ');  | 
70 |  | -            $error        = 'Comment refers to a FIXME task';  | 
71 |  | -            $data         = [$fixmeMessage];  | 
72 |  | -            if ($fixmeMessage !== '') {  | 
73 |  | -                $type   = 'TaskFound';  | 
74 |  | -                $error .= ' "%s"';  | 
 | 61 | + | 
 | 62 | +        if (preg_match('/(?:\A|[^\p{L}]+)fixme([^\p{L}]+(.*)|\Z)/ui', $content, $matches) !== 1) {  | 
 | 63 | +            return;  | 
 | 64 | +        }  | 
 | 65 | + | 
 | 66 | +        $fixmeMessage = trim($matches[1]);  | 
 | 67 | +        // Clear whitespace and some common characters not required at  | 
 | 68 | +        // the end of a to-do message to make the warning more informative.  | 
 | 69 | +        $fixmeMessage = trim($fixmeMessage, '-:[](). ');  | 
 | 70 | + | 
 | 71 | +        if ($tokens[$stackPtr]['code'] === T_DOC_COMMENT_TAG  | 
 | 72 | +            && $fixmeMessage === ''  | 
 | 73 | +        ) {  | 
 | 74 | +            $nextNonEmpty = $phpcsFile->findNext(T_DOC_COMMENT_WHITESPACE, ($stackPtr + 1), null, true);  | 
 | 75 | +            if ($nextNonEmpty !== false  | 
 | 76 | +                && $tokens[$nextNonEmpty]['code'] === T_DOC_COMMENT_STRING  | 
 | 77 | +            ) {  | 
 | 78 | +                $fixmeMessage = trim($tokens[$nextNonEmpty]['content'], '-:[](). ');  | 
75 | 79 |             }  | 
 | 80 | +        }  | 
76 | 81 | 
 
  | 
77 |  | -            $phpcsFile->addError($error, $stackPtr, $type, $data);  | 
 | 82 | +        $error = 'Comment refers to a FIXME task';  | 
 | 83 | +        $type  = 'CommentFound';  | 
 | 84 | +        $data  = [$fixmeMessage];  | 
 | 85 | +        if ($fixmeMessage !== '') {  | 
 | 86 | +            $error .= ' "%s"';  | 
 | 87 | +            $type   = 'TaskFound';  | 
78 | 88 |         }  | 
79 | 89 | 
 
  | 
 | 90 | +        $phpcsFile->addError($error, $stackPtr, $type, $data);  | 
 | 91 | + | 
80 | 92 |     }//end process()  | 
81 | 93 | 
 
  | 
82 | 94 | 
 
  | 
 | 
0 commit comments