Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/Type/IntersectionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -981,7 +981,12 @@
}
}

if ($this->isList()->yes() && $this->getIterableValueType()->isArray()->yes()) {
if (
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the long term, this IF should not be here I think.

it feels like a workaround from a time in which setExistingOffsetValueType did not yet exist.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we try removing this if and find the right place to fix ?

Cause setting an Int key to a List shouldnt always keep the list

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't want to change too many array related stuff atm - I don't want make ondrejs' work harder than necessary.

$this->isList()->yes()
&& $offsetType !== null
&& $offsetType->toArrayKey()->isInteger()->yes()

Check warning on line 987 in src/Type/IntersectionType.php

View workflow job for this annotation

GitHub Actions / Mutation Testing (8.4, ubuntu-latest)

Escaped Mutant for Mutator "PHPStan\Infection\TrinaryLogicMutator": @@ @@ if ( $this->isList()->yes() && $offsetType !== null - && $offsetType->toArrayKey()->isInteger()->yes() + && !$offsetType->toArrayKey()->isInteger()->no() && $this->getIterableValueType()->isArray()->yes() ) { $result = TypeCombinator::intersect($result, new AccessoryArrayListType());

Check warning on line 987 in src/Type/IntersectionType.php

View workflow job for this annotation

GitHub Actions / Mutation Testing (8.3, ubuntu-latest)

Escaped Mutant for Mutator "PHPStan\Infection\TrinaryLogicMutator": @@ @@ if ( $this->isList()->yes() && $offsetType !== null - && $offsetType->toArrayKey()->isInteger()->yes() + && !$offsetType->toArrayKey()->isInteger()->no() && $this->getIterableValueType()->isArray()->yes() ) { $result = TypeCombinator::intersect($result, new AccessoryArrayListType());
&& $this->getIterableValueType()->isArray()->yes()
) {
$result = TypeCombinator::intersect($result, new AccessoryArrayListType());
}

Expand Down
2 changes: 2 additions & 0 deletions tests/PHPStan/Analyser/nsrt/bug-10089.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ class Test
protected function create_matrix(int $size): array
{
$size = min(8, $size);
assertType('int<min, 8>', $size);
$matrix = [];
for ($i = 0; $i < $size; $i++) {
assertType('int<0, 7>', $i);
$matrix[] = array_fill(0, $size, 0);
}

Expand Down
38 changes: 38 additions & 0 deletions tests/PHPStan/Analyser/nsrt/bug-13629.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php declare(strict_types = 1);

namespace Bug13629;

use function PHPStan\Testing\assertType;

/**
* @param array<string, list<array{xmlNamespace: string, namespace: string, name: string}>> $xsdFiles
* @param array<string, list<array{xmlNamespace: string, namespace: string, name: string}>> $groupedByNamespace
* @param array<string, list<string>> $extraNamespaces
*/
function test(array $xsdFiles, array $groupedByNamespace, array $extraNamespaces): void {
foreach ($extraNamespaces as $mergedNamespace) {
if (count($mergedNamespace) < 2) {
continue;
}

$targetNamespace = end($mergedNamespace);
if (!isset($groupedByNamespace[$targetNamespace])) {
continue;
}
$xmlNamespace = $groupedByNamespace[$targetNamespace][0]['xmlNamespace'];

assertType('string', $xmlNamespace);
assertType('non-empty-list<string>&hasOffsetValue(1, string)', $mergedNamespace);

$xsdFiles[$xmlNamespace] = [];
foreach ($mergedNamespace as $namespace) {
foreach ($groupedByNamespace[$namespace] ?? [] as $viewHelper) {
assertType('string', $viewHelper['name']);
$xsdFiles[$xmlNamespace][$viewHelper['name']] = $viewHelper;
}
}
// After assigning with string keys ($viewHelper['name']), $xsdFiles[$xmlNamespace] should NOT be a list
assertType('array<int<0, max>|string, array{xmlNamespace: string, namespace: string, name: string}>', $xsdFiles[$xmlNamespace]);
$xsdFiles[$xmlNamespace] = array_values($xsdFiles[$xmlNamespace]);
}
}
Loading