From afa124576afa6f3f3aa0ae34e527e37029e4e0dc Mon Sep 17 00:00:00 2001 From: jrfnl Date: Tue, 18 Feb 2020 03:00:08 +0100 Subject: [PATCH] VariableAnalysisSniff::checkForPassByReferenceFunctionCall(): fix comment tolerance PHP ignores comments in unexpected/unconventional places and so should the sniff. Includes adjusting an existing unit test. Without the fix, the adjusted unit test would cause test failures. --- VariableAnalysis/Sniffs/CodeAnalysis/VariableAnalysisSniff.php | 2 +- .../CodeAnalysis/fixtures/FunctionWithReferenceFixture.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/VariableAnalysis/Sniffs/CodeAnalysis/VariableAnalysisSniff.php b/VariableAnalysis/Sniffs/CodeAnalysis/VariableAnalysisSniff.php index 1a1e7824..9518e9c8 100644 --- a/VariableAnalysis/Sniffs/CodeAnalysis/VariableAnalysisSniff.php +++ b/VariableAnalysis/Sniffs/CodeAnalysis/VariableAnalysisSniff.php @@ -1075,7 +1075,7 @@ protected function checkForPassByReferenceFunctionCall(File $phpcsFile, $stackPt if ($ptr === $stackPtr) { continue; } - if ($tokens[$ptr]['code'] !== T_WHITESPACE) { + if (isset(Tokens::$emptyTokens[$tokens[$ptr]['code']]) === false) { return false; } } diff --git a/VariableAnalysis/Tests/CodeAnalysis/fixtures/FunctionWithReferenceFixture.php b/VariableAnalysis/Tests/CodeAnalysis/fixtures/FunctionWithReferenceFixture.php index 641f2294..2f0bd8bb 100644 --- a/VariableAnalysis/Tests/CodeAnalysis/fixtures/FunctionWithReferenceFixture.php +++ b/VariableAnalysis/Tests/CodeAnalysis/fixtures/FunctionWithReferenceFixture.php @@ -32,7 +32,7 @@ function function_with_pass_by_reference_calls() { echo $matches; echo $needle; echo $haystack; - preg_match('/(abc)/', 'defabcghi', $matches); + preg_match('/(abc)/', 'defabcghi', /* comment */ $matches); preg_match($needle, 'defabcghi', $matches); preg_match('/(abc)/', $haystack, $matches); echo $matches;