From 15a56167df72c431d02af1823461b6ed178c8ffd Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Wed, 14 May 2025 16:23:24 +0200 Subject: [PATCH 1/9] DuplicateKeysInLiteralArraysRule: Fixed union type handling --- .../DuplicateKeysInLiteralArraysRule.php | 16 ++++++++++--- .../DuplicateKeysInLiteralArraysRuleTest.php | 4 ++++ .../Rules/Arrays/data/duplicate-keys.php | 23 +++++++++++++++++++ 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/src/Rules/Arrays/DuplicateKeysInLiteralArraysRule.php b/src/Rules/Arrays/DuplicateKeysInLiteralArraysRule.php index 7e54a2cb15..0151320928 100644 --- a/src/Rules/Arrays/DuplicateKeysInLiteralArraysRule.php +++ b/src/Rules/Arrays/DuplicateKeysInLiteralArraysRule.php @@ -9,6 +9,7 @@ use PHPStan\Rules\Rule; use PHPStan\Rules\RuleErrorBuilder; use PHPStan\Type\Constant\ConstantIntegerType; +use PHPStan\Type\TypeCombinator; use function array_keys; use function count; use function implode; @@ -49,6 +50,7 @@ public function processNode(Node $node, Scope $scope): array * - False means a non-scalar value was encountered and we cannot be sure of the next keys. */ $autoGeneratedIndex = null; + $overallKeyType = null; foreach ($node->getItemNodes() as $itemNode) { $item = $itemNode->getArrayItem(); if ($item === null) { @@ -75,6 +77,8 @@ public function processNode(Node $node, Scope $scope): array $autoGeneratedIndex = $autoGeneratedIndex === null ? $arrayKeyValues[0] : max($autoGeneratedIndex, $arrayKeyValues[0]); + } elseif (count($arrayKeyValues) > 1) { + $autoGeneratedIndex = false; } } @@ -84,6 +88,14 @@ public function processNode(Node $node, Scope $scope): array continue; } + if ($overallKeyType === null) { + $duplicate = false; + $overallKeyType = $keyType; + } else { + $duplicate = $overallKeyType->isSuperTypeOf($keyType)->yes(); + $overallKeyType = TypeCombinator::union($overallKeyType, $keyType); + } + foreach ($keyValues as $value) { $printedValue = $key !== null ? $this->exprPrinter->printExpr($key) @@ -94,9 +106,7 @@ public function processNode(Node $node, Scope $scope): array $valueLines[$value] = $item->getStartLine(); } - $previousCount = count($values); - $values[$value] = $printedValue; - if ($previousCount !== count($values)) { + if (!$duplicate) { continue; } diff --git a/tests/PHPStan/Rules/Arrays/DuplicateKeysInLiteralArraysRuleTest.php b/tests/PHPStan/Rules/Arrays/DuplicateKeysInLiteralArraysRuleTest.php index 6d775a2f7c..0ac3d9a6ec 100644 --- a/tests/PHPStan/Rules/Arrays/DuplicateKeysInLiteralArraysRuleTest.php +++ b/tests/PHPStan/Rules/Arrays/DuplicateKeysInLiteralArraysRuleTest.php @@ -73,6 +73,10 @@ public function testDuplicateKeys(): void 'Array has 2 duplicate keys with value \'key\' (\'key\', $key2).', 105, ], + [ + "Array has 2 duplicate keys with value 'bar' (\$key, 'bar').", + 128, + ], ]); } diff --git a/tests/PHPStan/Rules/Arrays/data/duplicate-keys.php b/tests/PHPStan/Rules/Arrays/data/duplicate-keys.php index 06dbbeb0f5..32848b8c3d 100644 --- a/tests/PHPStan/Rules/Arrays/data/duplicate-keys.php +++ b/tests/PHPStan/Rules/Arrays/data/duplicate-keys.php @@ -107,4 +107,27 @@ public function doUnionKeys(string $key): void ]; } + /** + * @param 'foo'|'bar' $key + */ + public function maybeDuplicate(string $key): void + { + $a = [ + 'foo' => 'foo', + $key => 'foo|bar', + ]; + } + + /** + * @param 'foo'|'bar' $key + */ + public function sureDuplicate(string $key): void + { + $a = [ + 'foo' => 'foo', + $key => 'foo|bar', + 'bar' => 'bar', + ]; + } + } From c6c286d7412c9cf1f1a89a49429ed6c2e4ecc608 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Wed, 14 May 2025 20:17:01 +0200 Subject: [PATCH 2/9] fix --- .../DuplicateKeysInLiteralArraysRule.php | 39 +++++++--- .../DuplicateKeysInLiteralArraysRuleTest.php | 17 ++++ tests/PHPStan/Rules/Arrays/data/bug-13013.php | 77 +++++++++++++++++++ .../Rules/Arrays/data/duplicate-keys.php | 24 ++++++ 4 files changed, 147 insertions(+), 10 deletions(-) create mode 100644 tests/PHPStan/Rules/Arrays/data/bug-13013.php diff --git a/src/Rules/Arrays/DuplicateKeysInLiteralArraysRule.php b/src/Rules/Arrays/DuplicateKeysInLiteralArraysRule.php index 0151320928..ee838fd626 100644 --- a/src/Rules/Arrays/DuplicateKeysInLiteralArraysRule.php +++ b/src/Rules/Arrays/DuplicateKeysInLiteralArraysRule.php @@ -9,7 +9,9 @@ use PHPStan\Rules\Rule; use PHPStan\Rules\RuleErrorBuilder; use PHPStan\Type\Constant\ConstantIntegerType; +use PHPStan\Type\NeverType; use PHPStan\Type\TypeCombinator; +use PHPStan\Type\UnionType; use function array_keys; use function count; use function implode; @@ -37,7 +39,6 @@ public function getNodeType(): string public function processNode(Node $node, Scope $scope): array { - $values = []; $duplicateKeys = []; $printedValues = []; $valueLines = []; @@ -50,7 +51,7 @@ public function processNode(Node $node, Scope $scope): array * - False means a non-scalar value was encountered and we cannot be sure of the next keys. */ $autoGeneratedIndex = null; - $overallKeyType = null; + $seenKeys = []; foreach ($node->getItemNodes() as $itemNode) { $item = $itemNode->getArrayItem(); if ($item === null) { @@ -77,8 +78,6 @@ public function processNode(Node $node, Scope $scope): array $autoGeneratedIndex = $autoGeneratedIndex === null ? $arrayKeyValues[0] : max($autoGeneratedIndex, $arrayKeyValues[0]); - } elseif (count($arrayKeyValues) > 1) { - $autoGeneratedIndex = false; } } @@ -88,12 +87,32 @@ public function processNode(Node $node, Scope $scope): array continue; } - if ($overallKeyType === null) { - $duplicate = false; - $overallKeyType = $keyType; - } else { - $duplicate = $overallKeyType->isSuperTypeOf($keyType)->yes(); - $overallKeyType = TypeCombinator::union($overallKeyType, $keyType); + $duplicate = false; + $newValuesType = $keyType; + foreach ($seenKeys as $seenKey) { + if ($seenKey instanceof UnionType) { + continue; + } + $newValuesType = TypeCombinator::remove($newValuesType, $seenKey); + + if ( + !($newValuesType instanceof NeverType) + && !$newValuesType->isSuperTypeOf($seenKey)->yes() + ) { + continue; + } + + $duplicate = true; + } + + if (!$newValuesType instanceof UnionType) { + foreach ($seenKeys as $k => $seenKey) { + $seenKeys[$k] = TypeCombinator::remove($seenKey, $newValuesType); + } + } + + if (!$newValuesType instanceof NeverType) { + $seenKeys[] = $newValuesType; } foreach ($keyValues as $value) { diff --git a/tests/PHPStan/Rules/Arrays/DuplicateKeysInLiteralArraysRuleTest.php b/tests/PHPStan/Rules/Arrays/DuplicateKeysInLiteralArraysRuleTest.php index 0ac3d9a6ec..de7241a2c4 100644 --- a/tests/PHPStan/Rules/Arrays/DuplicateKeysInLiteralArraysRuleTest.php +++ b/tests/PHPStan/Rules/Arrays/DuplicateKeysInLiteralArraysRuleTest.php @@ -77,7 +77,24 @@ public function testDuplicateKeys(): void "Array has 2 duplicate keys with value 'bar' (\$key, 'bar').", 128, ], + [ + "Array has 2 duplicate keys with value 'bar' (\$key, 'bar').", + 139, + ], + [ + "Array has 2 duplicate keys with value 'foo' ('foo', \$key).", + 151, + ], + [ + "Array has 2 duplicate keys with value 'bar' ('bar', \$key).", + 152, + ], ]); } + public function testBug13013(): void + { + $this->analyse([__DIR__ . '/data/bug-13013.php'], []); + } + } diff --git a/tests/PHPStan/Rules/Arrays/data/bug-13013.php b/tests/PHPStan/Rules/Arrays/data/bug-13013.php new file mode 100644 index 0000000000..dd5180869c --- /dev/null +++ b/tests/PHPStan/Rules/Arrays/data/bug-13013.php @@ -0,0 +1,77 @@ +> + */ + public array $mailsGroupedByTemplate; + + /** + * @var array> + */ + protected array $mailCounts; + + private function __construct() + { + $this->mailsGroupedByTemplate = []; + $this->mailCounts = []; + } + + public function countMailStates(): void + { + foreach ($this->mailsGroupedByTemplate as $templateId => $mails) { + $this->mailCounts[$templateId] = [ + MailStatus::notActive()->code => 0, + MailStatus::simulation()->code => 0, + MailStatus::active()->code => 0, + ]; + } + } +} + +final class MailStatus +{ + private const CODE_NOT_ACTIVE = 0; + + private const CODE_SIMULATION = 1; + + private const CODE_ACTIVE = 2; + + /** + * @var self::CODE_* + */ + public int $code; + + public string $name; + + public string $description; + + /** + * @param self::CODE_* $status + */ + public function __construct(int $status, string $name, string $description) + { + $this->code = $status; + $this->name = $name; + $this->description = $description; + } + + public static function notActive(): self + { + return new self(self::CODE_NOT_ACTIVE, _('Pausiert'), _('Es findet kein Mailversand an Kunden statt')); + } + + public static function simulation(): self + { + return new self(self::CODE_SIMULATION, _('Simulation'), _('Wenn Template zugewiesen, werden im Simulationsmodus E-Mails nur in der Datenbank gespeichert und nicht an den Kunden gesendet')); + } + + public static function active(): self + { + return new self(self::CODE_ACTIVE, _('Aktiv'), _('Wenn Template zugewiesen, findet Mailversand an Kunden statt')); + } + +} diff --git a/tests/PHPStan/Rules/Arrays/data/duplicate-keys.php b/tests/PHPStan/Rules/Arrays/data/duplicate-keys.php index 32848b8c3d..e3b434ddbb 100644 --- a/tests/PHPStan/Rules/Arrays/data/duplicate-keys.php +++ b/tests/PHPStan/Rules/Arrays/data/duplicate-keys.php @@ -130,4 +130,28 @@ public function sureDuplicate(string $key): void ]; } + /** + * @param 'foo'|'bar' $key + */ + public function sureDuplicate2(string $key): void + { + $a = [ + $key => 'foo|bar', + 'foo' => 'foo', + 'bar' => 'bar', + ]; + } + + /** + * @param 'foo'|'bar' $key + */ + public function sureDuplicate3(string $key): void + { + $a = [ + 'foo' => 'foo', + 'bar' => 'bar', + $key => 'foo|bar', + ]; + } + } From 536dc8821d8e4c52aa3e7b4ee1081bf433727202 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Wed, 14 May 2025 20:21:02 +0200 Subject: [PATCH 3/9] more tests --- .../DuplicateKeysInLiteralArraysRuleTest.php | 4 ++++ .../Rules/Arrays/data/duplicate-keys.php | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/tests/PHPStan/Rules/Arrays/DuplicateKeysInLiteralArraysRuleTest.php b/tests/PHPStan/Rules/Arrays/DuplicateKeysInLiteralArraysRuleTest.php index de7241a2c4..e64c6c9eaf 100644 --- a/tests/PHPStan/Rules/Arrays/DuplicateKeysInLiteralArraysRuleTest.php +++ b/tests/PHPStan/Rules/Arrays/DuplicateKeysInLiteralArraysRuleTest.php @@ -89,6 +89,10 @@ public function testDuplicateKeys(): void "Array has 2 duplicate keys with value 'bar' ('bar', \$key).", 152, ], + [ + "Array has 2 duplicate keys with value 'baz' (\$key, 'baz').", + 171, + ], ]); } diff --git a/tests/PHPStan/Rules/Arrays/data/duplicate-keys.php b/tests/PHPStan/Rules/Arrays/data/duplicate-keys.php index e3b434ddbb..35d7d118fa 100644 --- a/tests/PHPStan/Rules/Arrays/data/duplicate-keys.php +++ b/tests/PHPStan/Rules/Arrays/data/duplicate-keys.php @@ -154,4 +154,22 @@ public function sureDuplicate3(string $key): void ]; } + /** + * @param 'foo'|'bar'|'baz' $key + */ + public function sureDuplicate4(string $key): void + { + $a = [ + 'foo' => 'foo', + 'bar' => 'bar', + $key => 'foo|bar', + ]; + + $b = [ + 'foo' => 'foo', + 'bar' => 'bar', + $key => 'foo|bar', + 'baz' => 'baz', + ]; + } } From 20325e2a3b69beca3c3fae78a34b0ad733e2fe9f Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Wed, 14 May 2025 20:22:34 +0200 Subject: [PATCH 4/9] Update duplicate-keys.php --- tests/PHPStan/Rules/Arrays/data/duplicate-keys.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/PHPStan/Rules/Arrays/data/duplicate-keys.php b/tests/PHPStan/Rules/Arrays/data/duplicate-keys.php index 35d7d118fa..7a73af9da9 100644 --- a/tests/PHPStan/Rules/Arrays/data/duplicate-keys.php +++ b/tests/PHPStan/Rules/Arrays/data/duplicate-keys.php @@ -162,13 +162,13 @@ public function sureDuplicate4(string $key): void $a = [ 'foo' => 'foo', 'bar' => 'bar', - $key => 'foo|bar', + $key => 'foo|bar|baz', ]; $b = [ 'foo' => 'foo', 'bar' => 'bar', - $key => 'foo|bar', + $key => 'foo|bar|baz', 'baz' => 'baz', ]; } From 672ea350a05c1e6cb4283f648f454c88681cc3a9 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Wed, 14 May 2025 20:35:46 +0200 Subject: [PATCH 5/9] refactor --- .../DuplicateKeysInLiteralArraysRule.php | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/Rules/Arrays/DuplicateKeysInLiteralArraysRule.php b/src/Rules/Arrays/DuplicateKeysInLiteralArraysRule.php index ee838fd626..30de60acd9 100644 --- a/src/Rules/Arrays/DuplicateKeysInLiteralArraysRule.php +++ b/src/Rules/Arrays/DuplicateKeysInLiteralArraysRule.php @@ -96,22 +96,20 @@ public function processNode(Node $node, Scope $scope): array $newValuesType = TypeCombinator::remove($newValuesType, $seenKey); if ( - !($newValuesType instanceof NeverType) - && !$newValuesType->isSuperTypeOf($seenKey)->yes() + $newValuesType instanceof NeverType + || $newValuesType->isSuperTypeOf($seenKey)->yes() ) { - continue; - } - - $duplicate = true; - } - - if (!$newValuesType instanceof UnionType) { - foreach ($seenKeys as $k => $seenKey) { - $seenKeys[$k] = TypeCombinator::remove($seenKey, $newValuesType); + $duplicate = true; + break; } } if (!$newValuesType instanceof NeverType) { + if (!$newValuesType instanceof UnionType) { + foreach ($seenKeys as $k => $seenKey) { + $seenKeys[$k] = TypeCombinator::remove($seenKey, $newValuesType); + } + } $seenKeys[] = $newValuesType; } From 03cb092b31aa3f89eb605a62712e89c2dce6bcd7 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Wed, 14 May 2025 21:45:39 +0200 Subject: [PATCH 6/9] faster --- .../DuplicateKeysInLiteralArraysRule.php | 36 +++++++++++++------ 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/src/Rules/Arrays/DuplicateKeysInLiteralArraysRule.php b/src/Rules/Arrays/DuplicateKeysInLiteralArraysRule.php index 30de60acd9..c7ea6d3a97 100644 --- a/src/Rules/Arrays/DuplicateKeysInLiteralArraysRule.php +++ b/src/Rules/Arrays/DuplicateKeysInLiteralArraysRule.php @@ -52,6 +52,7 @@ public function processNode(Node $node, Scope $scope): array */ $autoGeneratedIndex = null; $seenKeys = []; + $seenUnions = []; foreach ($node->getItemNodes() as $itemNode) { $item = $itemNode->getArrayItem(); if ($item === null) { @@ -88,29 +89,42 @@ public function processNode(Node $node, Scope $scope): array } $duplicate = false; - $newValuesType = $keyType; + $newValuesType = $keyValues; foreach ($seenKeys as $seenKey) { - if ($seenKey instanceof UnionType) { - continue; + $offset = array_search($seenKey, $newValuesType, true); + if ($offset !== false) { + unset($newValuesType[$offset]); } - $newValuesType = TypeCombinator::remove($newValuesType, $seenKey); if ( - $newValuesType instanceof NeverType - || $newValuesType->isSuperTypeOf($seenKey)->yes() + $newValuesType === [] ) { $duplicate = true; break; } } - if (!$newValuesType instanceof NeverType) { - if (!$newValuesType instanceof UnionType) { - foreach ($seenKeys as $k => $seenKey) { - $seenKeys[$k] = TypeCombinator::remove($seenKey, $newValuesType); + if ( + $newValuesType !== [] + ) { + if (count($newValuesType) === 1) { + $newValue = $newValuesType[array_key_first($newValuesType)]; + foreach ($seenUnions as $k => $seenKey) { + $offset = array_search($newValue, $seenKey, true); + if ($offset !== false) { + unset($seenUnions[$k][$offset]); + + if (count($seenUnions[$k]) === 1) { + $ukey = array_key_first($seenUnions[$k]); + $seenKeys[] = $seenUnions[$k][$ukey]; + unset($seenUnions[$k]); + } + } } + $seenKeys[] = $newValue; + } else { + $seenUnions[] = $newValuesType; } - $seenKeys[] = $newValuesType; } foreach ($keyValues as $value) { From a1597e0f8e3415b5c80dc4fdbe741c5f3c2fb3eb Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Wed, 14 May 2025 22:20:20 +0200 Subject: [PATCH 7/9] cs --- .../DuplicateKeysInLiteralArraysRule.php | 45 ++++++++++--------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/src/Rules/Arrays/DuplicateKeysInLiteralArraysRule.php b/src/Rules/Arrays/DuplicateKeysInLiteralArraysRule.php index c7ea6d3a97..9cde4ea48f 100644 --- a/src/Rules/Arrays/DuplicateKeysInLiteralArraysRule.php +++ b/src/Rules/Arrays/DuplicateKeysInLiteralArraysRule.php @@ -9,10 +9,9 @@ use PHPStan\Rules\Rule; use PHPStan\Rules\RuleErrorBuilder; use PHPStan\Type\Constant\ConstantIntegerType; -use PHPStan\Type\NeverType; -use PHPStan\Type\TypeCombinator; -use PHPStan\Type\UnionType; +use function array_key_first; use function array_keys; +use function array_search; use function count; use function implode; use function is_int; @@ -89,15 +88,15 @@ public function processNode(Node $node, Scope $scope): array } $duplicate = false; - $newValuesType = $keyValues; + $newValues = $keyValues; foreach ($seenKeys as $seenKey) { - $offset = array_search($seenKey, $newValuesType, true); + $offset = array_search($seenKey, $newValues, true); if ($offset !== false) { - unset($newValuesType[$offset]); + unset($newValues[$offset]); } if ( - $newValuesType === [] + $newValues === [] ) { $duplicate = true; break; @@ -105,25 +104,29 @@ public function processNode(Node $node, Scope $scope): array } if ( - $newValuesType !== [] + $newValues !== [] ) { - if (count($newValuesType) === 1) { - $newValue = $newValuesType[array_key_first($newValuesType)]; - foreach ($seenUnions as $k => $seenKey) { - $offset = array_search($newValue, $seenKey, true); - if ($offset !== false) { - unset($seenUnions[$k][$offset]); - - if (count($seenUnions[$k]) === 1) { - $ukey = array_key_first($seenUnions[$k]); - $seenKeys[] = $seenUnions[$k][$ukey]; - unset($seenUnions[$k]); - } + if (count($newValues) === 1) { + $newValue = $newValues[array_key_first($newValues)]; + foreach ($seenUnions as $k => $union) { + $offset = array_search($newValue, $union, true); + if ($offset === false) { + continue; } + + unset($seenUnions[$k][$offset]); + + if (count($seenUnions[$k]) !== 1) { + continue; + } + + $ukey = array_key_first($seenUnions[$k]); + $seenKeys[] = $seenUnions[$k][$ukey]; + unset($seenUnions[$k]); } $seenKeys[] = $newValue; } else { - $seenUnions[] = $newValuesType; + $seenUnions[] = $newValues; } } From e2805d7be9f96611f497def5fbce7040f25aefc2 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Thu, 15 May 2025 09:35:39 +0200 Subject: [PATCH 8/9] tweak --- .../DuplicateKeysInLiteralArraysRule.php | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/Rules/Arrays/DuplicateKeysInLiteralArraysRule.php b/src/Rules/Arrays/DuplicateKeysInLiteralArraysRule.php index 9cde4ea48f..b8c0c2497a 100644 --- a/src/Rules/Arrays/DuplicateKeysInLiteralArraysRule.php +++ b/src/Rules/Arrays/DuplicateKeysInLiteralArraysRule.php @@ -89,23 +89,18 @@ public function processNode(Node $node, Scope $scope): array $duplicate = false; $newValues = $keyValues; - foreach ($seenKeys as $seenKey) { - $offset = array_search($seenKey, $newValues, true); - if ($offset !== false) { - unset($newValues[$offset]); + foreach ($newValues as $k => $newValue) { + if (array_search($newValue, $seenKeys, true) !== false) { + unset($newValues[$k]); } - if ( - $newValues === [] - ) { + if ($newValues === []) { $duplicate = true; break; } } - if ( - $newValues !== [] - ) { + if ($newValues !== []) { if (count($newValues) === 1) { $newValue = $newValues[array_key_first($newValues)]; foreach ($seenUnions as $k => $union) { @@ -116,12 +111,12 @@ public function processNode(Node $node, Scope $scope): array unset($seenUnions[$k][$offset]); + // turn a union into a seen key, when all its elements have been seen if (count($seenUnions[$k]) !== 1) { continue; } - $ukey = array_key_first($seenUnions[$k]); - $seenKeys[] = $seenUnions[$k][$ukey]; + $seenKeys[] = $seenUnions[$k][array_key_first($seenUnions[$k])]; unset($seenUnions[$k]); } $seenKeys[] = $newValue; From 35d0b02667ac9e43e9aa1ef76b091a4f4c24cc07 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Fri, 16 May 2025 09:58:21 +0200 Subject: [PATCH 9/9] regression test --- .../DuplicateKeysInLiteralArraysRuleTest.php | 5 ++++ tests/PHPStan/Rules/Arrays/data/bug-13022.php | 29 +++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 tests/PHPStan/Rules/Arrays/data/bug-13022.php diff --git a/tests/PHPStan/Rules/Arrays/DuplicateKeysInLiteralArraysRuleTest.php b/tests/PHPStan/Rules/Arrays/DuplicateKeysInLiteralArraysRuleTest.php index e64c6c9eaf..a01e02424d 100644 --- a/tests/PHPStan/Rules/Arrays/DuplicateKeysInLiteralArraysRuleTest.php +++ b/tests/PHPStan/Rules/Arrays/DuplicateKeysInLiteralArraysRuleTest.php @@ -101,4 +101,9 @@ public function testBug13013(): void $this->analyse([__DIR__ . '/data/bug-13013.php'], []); } + public function testBug13022(): void + { + $this->analyse([__DIR__ . '/data/bug-13022.php'], []); + } + } diff --git a/tests/PHPStan/Rules/Arrays/data/bug-13022.php b/tests/PHPStan/Rules/Arrays/data/bug-13022.php new file mode 100644 index 0000000000..22727c110a --- /dev/null +++ b/tests/PHPStan/Rules/Arrays/data/bug-13022.php @@ -0,0 +1,29 @@ + $object->getId(), + $targetId => 'info', + ]; + + // sql()->insert('tablename', $array); - example how this will be used +}