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

Bug #20225 array_merge() that takes more than one line generates error
Submitted: 2014-03-21 02:19 UTC
From: bkendig Assigned: squiz
Status: Closed Package: PHP_CodeSniffer (version 1.5.2)
PHP Version: 5.4.21 OS: Mac OS 10.9.2
Roadmaps: (Not assigned)    
Subscription  


 [2014-03-21 02:19 UTC] bkendig (Brian Kendig)
Description: ------------ When phpcs sees "array_merge(" immediately followed by a newline, it will throw a notice about an undefined offset in FunctionCallSignatureSniff.php. Expected result: ---------------- This example works, when array_merge( is not followed by a newline: test $ cat foo.php <?php array_merge(array('one')); test $ phpcs foo.php FILE: /Users/brkendig/test/foo.php ------------------------------------------------------------------------ -------- FOUND 1 ERROR(S) AFFECTING 1 LINE(S) ------------------------------------------------------------------------ -------- 1 | ERROR | Missing file doc comment ------------------------------------------------------------------------ -------- Time: 19 ms, Memory: 2.75Mb Actual result: -------------- This example fails: test $ cat bar.php <?php array_merge( array('one')); test $ phpcs bar.php PHP Notice: Undefined offset: -1 in /usr/local/zend/share/pear/PHP/CodeSniffer/Standards/PEAR/Sn iffs/Functions/FunctionCallSignatureSniff.php on line 245 PHP Stack trace: PHP 1. {main}() /usr/local/zend/bin/phpcs:0 PHP 2. PHP_CodeSniffer_CLI->process() /usr/local/zend/bin/phpcs:37 PHP 3. PHP_CodeSniffer->process() /usr/local/zend/share/pear/PHP/CodeSniffer/CLI.php:614 PHP 4. PHP_CodeSniffer->processFile() /usr/local/zend/share/pear/PHP/CodeSniffer.php:488 PHP 5. PHP_CodeSniffer->_processFile() /usr/local/zend/share/pear/PHP/CodeSniffer.php:1340 PHP 6. PHP_CodeSniffer_File->start() /usr/local/zend/share/pear/PHP/CodeSniffer.php:1460 PHP 7. PEAR_Sniffs_Functions_FunctionCallSignatureSniff- >process() /usr/local/zend/share/pear/PHP/CodeSniffer/File.php:506 PHP 8. PEAR_Sniffs_Functions_FunctionCallSignatureSniff- >processMultiLineCall() /usr/local/zend/share/pear/PHP/CodeSniffer/Standards/PEAR/Sn iffs/Functions/FunctionCallSignatureSniff.php:127 <font color=#ff0000> Notice: Undefined offset: -1 in /usr/local/zend/share/pear/PHP/CodeSniffer/Standards/PEAR/Sn iffs/Functions/FunctionCallSignatureSniff.php on line 245 Call Stack: 0.0003 229992 1. {main}() /usr/local/zend/bin/phpcs:0 0.0075 1190168 2. PHP_CodeSniffer_CLI->process() /usr/local/zend/bin/phpcs:37 0.0082 1237536 3. PHP_CodeSniffer->process() /usr/local/zend/share/pear/PHP/CodeSniffer/CLI.php:614 0.0181 2610824 4. PHP_CodeSniffer->processFile() /usr/local/zend/share/pear/PHP/CodeSniffer.php:488 0.0182 2611616 5. PHP_CodeSniffer->_processFile() /usr/local/zend/share/pear/PHP/CodeSniffer.php:1340 0.0182 2612344 6. PHP_CodeSniffer_File->start() /usr/local/zend/share/pear/PHP/CodeSniffer.php:1460 0.0192 2767008 7. PEAR_Sniffs_Functions_FunctionCallSignatureSniff->process() /usr/local/zend/share/pear/PHP/CodeSniffer/File.php:506 0.0193 2768192 8. PEAR_Sniffs_Functions_FunctionCallSignatureSniff- >processMultiLineCall() /usr/local/zend/share/pear/PHP/CodeSniffer/Standards/PEAR/Sn iffs/Functions/FunctionCallSignatureSniff.php:127 </font> FILE: /Users/brkendig/test/bar.php ------------------------------------------------------------------------ -------- FOUND 3 ERROR(S) AFFECTING 2 LINE(S) ------------------------------------------------------------------------ -------- 1 | ERROR | Missing file doc comment 2 | ERROR | Multi-line function call not indented correctly; expected 4 spaces | | but found 0 2 | ERROR | Closing parenthesis of a multi-line function call must be on a | | line by itself ------------------------------------------------------------------------ -------- Time: 21 ms, Memory: 2.75Mb

Comments

 [2014-03-24 05:56 UTC] squiz (Greg Sherwood)
-Status: Open +Status: Closed -Assigned To: +Assigned To: squiz
Fix committed to Github repo: https://github.com/squizlabs/PHP_CodeSniffer/commit/20be9de6417630c14f469197 785024fe785851fd Wasn't actually a problem with array_merge or how brackets are placed. Was a problem with having the function directly after the PHP open tag. When the sniff was looking to see how it should be indented, it ended up taking the pointer negative and then failing on the IF statement. Just added a sanity check and a unit test to expose it. If you've seen a problem with array_merge in code when it is not directly after the open tag, please let me know as I haven't been able to replicate one.