From 557756cd2b801573f5887b8a8462b89c49b9d35e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaroslav=20Hansl=C3=ADk?= Date: Thu, 8 Apr 2021 13:38:22 +0200 Subject: [PATCH] Squiz.PHP.DisallowMultipleAssignmentsSniff: Fixed false positive when assigment is after goto label --- .../Sniffs/PHP/DisallowMultipleAssignmentsSniff.php | 1 + .../Tests/PHP/DisallowMultipleAssignmentsUnitTest.inc | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/src/Standards/Squiz/Sniffs/PHP/DisallowMultipleAssignmentsSniff.php b/src/Standards/Squiz/Sniffs/PHP/DisallowMultipleAssignmentsSniff.php index 13525df673..4448d2445b 100644 --- a/src/Standards/Squiz/Sniffs/PHP/DisallowMultipleAssignmentsSniff.php +++ b/src/Standards/Squiz/Sniffs/PHP/DisallowMultipleAssignmentsSniff.php @@ -146,6 +146,7 @@ public function process(File $phpcsFile, $stackPtr) if ($tokens[$varToken]['code'] === T_VARIABLE || $tokens[$varToken]['code'] === T_OPEN_TAG + || $tokens[$varToken]['code'] === T_GOTO_LABEL || $tokens[$varToken]['code'] === T_INLINE_THEN || $tokens[$varToken]['code'] === T_INLINE_ELSE || $tokens[$varToken]['code'] === T_SEMICOLON diff --git a/src/Standards/Squiz/Tests/PHP/DisallowMultipleAssignmentsUnitTest.inc b/src/Standards/Squiz/Tests/PHP/DisallowMultipleAssignmentsUnitTest.inc index d76daa76b7..f657fb4a4c 100644 --- a/src/Standards/Squiz/Tests/PHP/DisallowMultipleAssignmentsUnitTest.inc +++ b/src/Standards/Squiz/Tests/PHP/DisallowMultipleAssignmentsUnitTest.inc @@ -98,3 +98,13 @@ function ($html) { return $all; }, $html); }; + + +function () { + $a = false; + + some_label: + + $b = getB(); +}; +