Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 3.7.2

Bug #12455 CodeSniffer treats content inside heredoc as PHP code
Submitted: 2007-11-15 19:39 UTC
From: sappyvcv Assigned: squiz
Status: Closed Package: PHP_CodeSniffer (version 1.0.0RC2)
PHP Version: 5.1.6 OS:
Roadmaps: 1.0.0RC3    
Subscription  


 [2007-11-15 19:39 UTC] sappyvcv (Matt Creenan)
Description: ------------ The Code Sniffer is treating content inside of a docblock as PHP code and sniffing it. Test script: --------------- <?php $test = <<<TEST function test(foo, bar) { alert(foo + bar); } TEST; ?> Expected result: ---------------- No errors produced aside from docblock warnings Actual result: -------------- -------------------------------------------------------------------------------- FOUND 4 ERROR(S) AND 0 WARNING(S) AFFECTING 2 LINE(S) -------------------------------------------------------------------------------- 4 | ERROR | Constants must be uppercase; expected FOO but found foo 4 | ERROR | Constants must be uppercase; expected BAR but found bar 5 | ERROR | Constants must be uppercase; expected FOO but found foo 5 | ERROR | Constants must be uppercase; expected BAR but found bar --------------------------------------------------------------------------------

Comments

 [2007-11-15 19:41 UTC] sappyvcv (Matt Creenan)
That should be "inside of a heredoc"
 [2007-11-15 20:01 UTC] sappyvcv (Matt Creenan)
I actually can't get the test case to reproduce, only a very large file with 2000-3000 lines of code that I can not legally upload. I'll working on getting a real test case.
 [2007-11-15 20:26 UTC] sappyvcv (Matt Creenan)
Real test case: <?php function foo() { $output = <<<EJS ads = '{$redirect_context}'; i = i+1; EJS; } ?>
 [2007-11-15 22:27 UTC] squiz (Greg Sherwood)
This bug has been fixed in CVS. If this was a documentation problem, the fix will appear on pear.php.net by the end of next Sunday (CET). If this was a problem with the pear.php.net website, the change should be live shortly. Otherwise, the fix will appear in the package's next release. Thank you for the report and for helping us make PEAR better. The reason for this is because token_get_all actually treats code within heredocs as valid PHP code. I've changed PHP_CodeSniffer to join all the tokens together and treat them as T_HEREDOC tokens (a new custom token) so they are ignored by all existing sniffs. The start and end heredoc token remain the same.