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

Request #19313 Make getTokensAsString() more robust by detecting incorrect length value
Submitted: 2012-03-02 06:37 UTC
From: klausi Assigned: squiz
Status: Closed Package: PHP_CodeSniffer (version SVN)
PHP Version: Irrelevant OS:
Roadmaps: (Not assigned)    
Subscription  


 [2012-03-02 06:37 UTC] klausi (Klaus Purer)
Description: ------------ If the length passed to the getTokensAsString() method exceeds the number of tokens in the file PHP notices will occur. For convenience this method should be more robust and stop assembling the string if the last token has been reached. Otherwise I always have to make sure myself that the limit is not exceeded before calling. Which is tedious.

Comments

 [2012-03-02 06:37 UTC] klausi (Klaus Purer)
 [2012-03-05 06:14 UTC] squiz (Greg Sherwood)
-Summary: Make PHP_CodeSniffer_File::getTokensAsString() more robust +Summary: Make getTokensAsString() more robust by detecting incorrect length value -Assigned To: +Assigned To: squiz
 [2012-03-05 06:18 UTC] squiz (Greg Sherwood)
-Status: Assigned +Status: Closed
Committed to git: https://github.com/squizlabs/PHP_CodeSniffer/commit/c946650634934347c96d9d1d2 99d4464c0c4757e Thanks a lot for the patch. I ended up doing it in a slightly different way so that the condition $i < $this->numTokens doesnt need to be checked on each iteration of the loop.