|
| 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 | +} |
0 commit comments