From d91641d6894b98de0c1c336f4683edc282903192 Mon Sep 17 00:00:00 2001 From: Greg Sherwood Date: Fri, 19 Feb 2016 11:11:33 +1100 Subject: [PATCH] Fixed bug #897 : Generic.Functions.CallTimePassByReference.NotAllowed false positive when short array syntax --- .../Functions/CallTimePassByReferenceSniff.php | 12 +++++++++++- .../Functions/CallTimePassByReferenceUnitTest.inc | 2 ++ package.xml | 1 + 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/CodeSniffer/Standards/Generic/Sniffs/Functions/CallTimePassByReferenceSniff.php b/CodeSniffer/Standards/Generic/Sniffs/Functions/CallTimePassByReferenceSniff.php index 3e1f6b2b58..27f3f54a56 100644 --- a/CodeSniffer/Standards/Generic/Sniffs/Functions/CallTimePassByReferenceSniff.php +++ b/CodeSniffer/Standards/Generic/Sniffs/Functions/CallTimePassByReferenceSniff.php @@ -98,11 +98,21 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) $closeBracket = $tokens[$openBracket]['parenthesis_closer']; $nextSeparator = $openBracket; - while (($nextSeparator = $phpcsFile->findNext(T_VARIABLE, ($nextSeparator + 1), $closeBracket)) !== false) { + $find = array( + T_VARIABLE, + T_OPEN_SHORT_ARRAY, + ); + + while (($nextSeparator = $phpcsFile->findNext($find, ($nextSeparator + 1), $closeBracket)) !== false) { if (isset($tokens[$nextSeparator]['nested_parenthesis']) === false) { continue; } + if ($tokens[$nextSeparator]['code'] === T_OPEN_SHORT_ARRAY) { + $nextSeparator = $tokens[$nextSeparator]['bracket_closer']; + continue; + } + // Make sure the variable belongs directly to this function call // and is not inside a nested function call or array. $brackets = $tokens[$nextSeparator]['nested_parenthesis']; diff --git a/CodeSniffer/Standards/Generic/Tests/Functions/CallTimePassByReferenceUnitTest.inc b/CodeSniffer/Standards/Generic/Tests/Functions/CallTimePassByReferenceUnitTest.inc index fdc0729cdb..186f2e8460 100644 --- a/CodeSniffer/Standards/Generic/Tests/Functions/CallTimePassByReferenceUnitTest.inc +++ b/CodeSniffer/Standards/Generic/Tests/Functions/CallTimePassByReferenceUnitTest.inc @@ -24,3 +24,5 @@ $foo(&$myvar); if (is_array($foo = &$this->bar())) { } + +Hooks::run( 'SecondaryDataUpdates', [ $title, $old, $recursive, $parserOutput, &$updates ] ); diff --git a/package.xml b/package.xml index 86ec804310..041b9dc305 100644 --- a/package.xml +++ b/package.xml @@ -65,6 +65,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> - Fixed bug #887 : Using curly braces for a shared CASE/DEFAULT statement can generate an error in PSR2 SwitchDeclaration - Fixed bug #889 : Closure inside catch/else/elseif causes indentation error - Fixed bug #890 : Function call inside returned short array value can cause indentation error inside CASE statements + - Fixed bug #897 : Generic.Functions.CallTimePassByReference.NotAllowed false positive when short array syntax