From bc42b82e5ce0f8872da6ab2db179d2ee5e0701a9 Mon Sep 17 00:00:00 2001 From: Mark Scherer Date: Sun, 25 Oct 2026 15:04:51 +0100 Subject: [PATCH] Compute the assoc-mode condition once in ArrayDeclarationSniff PHPStan 2.3.2 reports the repeated `multiLineIndentationMode === 'assoc'` check inside the item loop as always true (identical.alwaysTrue), which fails the stan job on every branch. The property can hold other values there, so it is a false positive, but the loop only needs the result of the check made before it. Evaluating it once removes the duplicate and the report without changing behavior. --- PhpCollective/Sniffs/Formatting/ArrayDeclarationSniff.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/PhpCollective/Sniffs/Formatting/ArrayDeclarationSniff.php b/PhpCollective/Sniffs/Formatting/ArrayDeclarationSniff.php index 4016f01..24b6203 100644 --- a/PhpCollective/Sniffs/Formatting/ArrayDeclarationSniff.php +++ b/PhpCollective/Sniffs/Formatting/ArrayDeclarationSniff.php @@ -593,9 +593,10 @@ protected function processMultiLineIndentation(File $phpcsFile, int $arrayStart, } } + $assocModeWithAssociative = $this->multiLineIndentationMode === 'assoc' && $hasAssociative; if ($this->multiLineIndentationMode === 'all') { $shouldProcess = true; - } elseif ($this->multiLineIndentationMode === 'assoc' && $hasAssociative) { + } elseif ($assocModeWithAssociative) { // In 'assoc' mode with associative items $shouldProcess = true; } elseif ($this->maxNonAssocItemsPerLine > 0 && $nonAssocCount > $this->maxNonAssocItemsPerLine) { @@ -613,7 +614,7 @@ protected function processMultiLineIndentation(File $phpcsFile, int $arrayStart, if ($this->multiLineIndentationMode === 'all') { $shouldFlag = true; - } elseif ($this->multiLineIndentationMode === 'assoc' && $hasAssociative) { + } elseif ($assocModeWithAssociative) { // In 'assoc' mode with mixed items, only skip non-associative if no limit exceeded if ($pair['is_associative'] || ($this->maxNonAssocItemsPerLine > 0 && $nonAssocCount > $this->maxNonAssocItemsPerLine)) { $shouldFlag = true;