Skip to content

Commit c41e609

Browse files
committed
Merge branch 2.1.x into 2.2.x
2 parents 80f1521 + cd904bb commit c41e609

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

src/Type/Accessory/AccessoryArrayListType.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,10 @@ public function setOffsetValueType(?Type $offsetType, Type $valueType, bool $uni
162162

163163
public function setExistingOffsetValueType(Type $offsetType, Type $valueType): Type
164164
{
165+
if ($this->hasOffsetValueType($offsetType)->no()) {
166+
return new ErrorType();
167+
}
168+
165169
return $this;
166170
}
167171

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug13629;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
/**
8+
* @param array<string, list<array{xmlNamespace: string, namespace: string, name: string}>> $xsdFiles
9+
* @param array<string, list<array{xmlNamespace: string, namespace: string, name: string}>> $groupedByNamespace
10+
* @param array<string, list<string>> $extraNamespaces
11+
*/
12+
function test(array $xsdFiles, array $groupedByNamespace, array $extraNamespaces): void {
13+
foreach ($extraNamespaces as $mergedNamespace) {
14+
if (count($mergedNamespace) < 2) {
15+
continue;
16+
}
17+
18+
$targetNamespace = end($mergedNamespace);
19+
if (!isset($groupedByNamespace[$targetNamespace])) {
20+
continue;
21+
}
22+
$xmlNamespace = $groupedByNamespace[$targetNamespace][0]['xmlNamespace'];
23+
24+
assertType('string', $xmlNamespace);
25+
assertType('non-empty-list<string>&hasOffsetValue(1, string)', $mergedNamespace);
26+
27+
$xsdFiles[$xmlNamespace] = [];
28+
foreach ($mergedNamespace as $namespace) {
29+
foreach ($groupedByNamespace[$namespace] ?? [] as $viewHelper) {
30+
$xsdFiles[$xmlNamespace][$viewHelper['name']] = $viewHelper;
31+
}
32+
}
33+
// After assigning with string keys ($viewHelper['name']), $xsdFiles[$xmlNamespace] should NOT be a list
34+
assertType('array<int<0, max>, array{xmlNamespace: string, namespace: string, name: string}>', $xsdFiles[$xmlNamespace]);
35+
$xsdFiles[$xmlNamespace] = array_values($xsdFiles[$xmlNamespace]);
36+
}
37+
}

tests/PHPStan/Rules/Functions/ArrayValuesRuleTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,9 @@ public function testFile(): void
8989
$this->analyse([__DIR__ . '/data/array_values_list.php'], $expectedErrors);
9090
}
9191

92+
public function testBug13629(): void
93+
{
94+
$this->analyse([__DIR__ . '/../../Analyser/nsrt/bug-13629.php'], []);
95+
}
96+
9297
}

0 commit comments

Comments
 (0)