Skip to content
Closed
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
11 changes: 7 additions & 4 deletions src/Analyser/ExprHandler/AssignHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -991,13 +991,16 @@ private function produceArrayDimFetchAssignValueToWrite(array $dimFetchStack, ar
$offsetType !== null
&& $arrayDimFetch !== null
&& $scope->hasExpressionType($arrayDimFetch)->yes()
&& !$offsetValueType->hasOffsetValueType($offsetType)->no()
) {
$hasOffsetType = null;
if ($offsetType instanceof ConstantStringType || $offsetType instanceof ConstantIntegerType) {
$hasOffsetType = new HasOffsetValueType($offsetType, $valueToWrite);
if ($offsetValueType->hasOffsetValueType($offsetType)->no()) {
$valueToWrite = $offsetValueType->setOffsetValueType($offsetType, $valueToWrite);
} else {
if ($offsetType instanceof ConstantStringType || $offsetType instanceof ConstantIntegerType) {
$hasOffsetType = new HasOffsetValueType($offsetType, $valueToWrite);
}
$valueToWrite = $offsetValueType->setExistingOffsetValueType($offsetType, $valueToWrite);
}
$valueToWrite = $offsetValueType->setExistingOffsetValueType($offsetType, $valueToWrite);

if ($valueToWrite->isArray()->yes()) {
if ($hasOffsetType !== null) {
Expand Down
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 (
$this->isList()->yes()
&& $valueType->isArray()->yes()

Check warning on line 986 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() - && $valueType->isArray()->yes() + && !$valueType->isArray()->no() && $offsetType !== null && IntegerRangeType::fromInterval(0, null)->isSuperTypeOf($offsetType)->yes() ) {

Check warning on line 986 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() - && $valueType->isArray()->yes() + && !$valueType->isArray()->no() && $offsetType !== null && IntegerRangeType::fromInterval(0, null)->isSuperTypeOf($offsetType)->yes() ) {
&& $offsetType !== null
&& IntegerRangeType::fromInterval(0, null)->isSuperTypeOf($offsetType)->yes()

Check warning on line 988 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\IsSuperTypeOfCalleeAndArgumentMutator": @@ @@ $this->isList()->yes() && $valueType->isArray()->yes() && $offsetType !== null - && IntegerRangeType::fromInterval(0, null)->isSuperTypeOf($offsetType)->yes() + && $offsetType->isSuperTypeOf(IntegerRangeType::fromInterval(0, null))->yes() ) { $result = TypeCombinator::intersect($result, new AccessoryArrayListType()); }

Check warning on line 988 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\IsSuperTypeOfCalleeAndArgumentMutator": @@ @@ $this->isList()->yes() && $valueType->isArray()->yes() && $offsetType !== null - && IntegerRangeType::fromInterval(0, null)->isSuperTypeOf($offsetType)->yes() + && $offsetType->isSuperTypeOf(IntegerRangeType::fromInterval(0, null))->yes() ) { $result = TypeCombinator::intersect($result, new AccessoryArrayListType()); }
) {
$result = TypeCombinator::intersect($result, new AccessoryArrayListType());
}

Expand Down
2 changes: 1 addition & 1 deletion tests/PHPStan/Analyser/nsrt/bug-10089.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ protected function create_matrix(int $size): array
$matrix[$size - 1][8] = 3;

// non-empty-array<int, non-empty-array<int, 0|3>&hasOffsetValue(8, 3)>
assertType('non-empty-list<non-empty-array<int<0, max>, 0|3>>', $matrix);
assertType('non-empty-array<int, non-empty-array<int<0, max>, 0|3>>', $matrix);

for ($i = 0; $i <= $size; $i++) {
if ($matrix[$i][8] === 0) {
Expand Down
37 changes: 37 additions & 0 deletions tests/PHPStan/Analyser/nsrt/bug-13629.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?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) {
$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