cvs: pear /PHP_CodeSniffer package.xml /PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/Formatting OutputBufferingIndentSniff.php
/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Formatting OutputBufferingIndentUnitTest.inc OutputBufferingIndentUnitTest.php

From: Date: Fri, 23 Mar 2007 03:30:57 +0000
Subject: cvs: pear /PHP_CodeSniffer package.xml /PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/Formatting OutputBufferingIndentSniff.php
/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Formatting OutputBufferingIndentUnitTest.inc OutputBufferingIndentUnitTest.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-45365@lists.php.net to get a copy of this message
squiz Fri Mar 23 03:30:57 2007 UTC Modified files: /pear/PHP_CodeSniffer package.xml /pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/Formatting OutputBufferingIndentSniff.php /pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Formatting OutputBufferingIndentUnitTest.inc OutputBufferingIndentUnitTest.php Log: Errors now thrown for using ob_get_clean/flush functions to end buffers in Squiz OutputBufferingIndentSniff http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/package.xml?r1=1.46&r2=1.47&diff_format=u Index: pear/PHP_CodeSniffer/package.xml diff -u pear/PHP_CodeSniffer/package.xml:1.46 pear/PHP_CodeSniffer/package.xml:1.47 --- pear/PHP_CodeSniffer/package.xml:1.46 Wed Mar 21 23:45:35 2007 +++ pear/PHP_CodeSniffer/package.xml Fri Mar 23 03:30:56 2007 @@ -48,6 +48,7 @@ - Errors now thrown for invalid @var tag values in Squiz VariableCommentSniff - Errors now thrown for missing doc comment in Squiz VariableCommentSniff - Errors now thrown for unspaced operators in FOR loop declarations in Squiz OperatorSpacingSniff + - Errors now thrown for using ob_get_clean/flush functions to end buffers in Squiz OutputBufferingIndentSniff </notes> <contents> <dir name="/"> http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/Formatting/OutputBufferingIndentSniff.php?r1=1.2&r2=1.3&diff_format=u Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/Formatting/OutputBufferingIndentSniff.php diff -u pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/Formatting/OutputBufferingIndentSniff.php:1.2 pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/Formatting/OutputBufferingIndentSniff.php:1.3 --- pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/Formatting/OutputBufferingIndentSniff.php:1.2 Wed Jan 10 03:14:44 2007 +++ pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Sniffs/Formatting/OutputBufferingIndentSniff.php Fri Mar 23 03:30:56 2007 @@ -10,7 +10,7 @@ * @author Marc McIntyre <mmcintyre@squiz.net> * @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600) * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence - * @version CVS: $Id: OutputBufferingIndentSniff.php,v 1.2 2007/01/10 03:14:44 squiz Exp $ + * @version CVS: $Id: OutputBufferingIndentSniff.php,v 1.3 2007/03/23 03:30:56 squiz Exp $ * @link http://pear.php.net/package/PHP_CodeSniffer */ @@ -64,11 +64,24 @@ } $bufferEnd = $stackPtr; - while (($bufferEnd = $phpcsFile->findNext(array(T_STRING), ($bufferEnd + 1), null, false)) !== false) { + while (($bufferEnd = $phpcsFile->findNext(array(T_STRING, T_FUNCTION), ($bufferEnd + 1), null, false)) !== false) { + if ($tokens[$bufferEnd]['code'] === T_FUNCTION) { + // We should not cross funtions or move into functions. + $bufferEnd = false; + break; + } + $stringContent = $tokens[$bufferEnd]['content']; if (($stringContent === 'ob_end_clean') || ($stringContent === 'ob_end_flush')) { break; } + + if (($stringContent === 'ob_get_clean') || ($stringContent === 'ob_get_flush')) { + // Generate the error because the functions are not allowed, but + // continue to check the indentation. + $phpcsFile->addError('Output buffering must be closed using ob_end_clean or ob_end_flush', $bufferEnd); + break; + } } if ($bufferEnd === false) { http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Formatting/OutputBufferingIndentUnitTest.inc?r1=1.2&r2=1.3&diff_format=u Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Formatting/OutputBufferingIndentUnitTest.inc diff -u pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Formatting/OutputBufferingIndentUnitTest.inc:1.2 pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Formatting/OutputBufferingIndentUnitTest.inc:1.3 --- pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Formatting/OutputBufferingIndentUnitTest.inc:1.2 Thu Jan 4 02:53:35 2007 +++ pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Formatting/OutputBufferingIndentUnitTest.inc Fri Mar 23 03:30:56 2007 @@ -27,6 +27,25 @@ // Hi. ob_end_clean(); +function myFunc1() +{ + ob_start(); + echo 'hello'; + $content = ob_get_clean(); + + if ($blah) { + echo 'blah'; + } +} + +function myFunc2() +{ + ob_start(); + echo 'hello'; + $content = ob_get_contents(); + ob_end_clean(); +} + ob_start(); echo $hello; ?> http://cvs.php.net/viewvc.cgi/pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Formatting/OutputBufferingIndentUnitTest.php?r1=1.2&r2=1.3&diff_format=u Index: pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Formatting/OutputBufferingIndentUnitTest.php diff -u pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Formatting/OutputBufferingIndentUnitTest.php:1.2 pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Formatting/OutputBufferingIndentUnitTest.php:1.3 --- pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Formatting/OutputBufferingIndentUnitTest.php:1.2 Thu Jan 4 02:53:35 2007 +++ pear/PHP_CodeSniffer/CodeSniffer/Standards/Squiz/Tests/Formatting/OutputBufferingIndentUnitTest.php Fri Mar 23 03:30:56 2007 @@ -10,7 +10,7 @@ * @author Marc McIntyre <mmcintyre@squiz.net> * @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600) * @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence - * @version CVS: $Id: OutputBufferingIndentUnitTest.php,v 1.2 2007/01/04 02:53:35 squiz Exp $ + * @version CVS: $Id: OutputBufferingIndentUnitTest.php,v 1.3 2007/03/23 03:30:56 squiz Exp $ * @link http://pear.php.net/package/PHP_CodeSniffer */ @@ -49,7 +49,9 @@ 12 => 1, 24 => 1, 25 => 1, - 30 => 1, + 33 => 1, + 34 => 2, + 49 => 1, ); }//end getErrorList()

« previous php.pear.cvs (#45365) next »