Skip to content
Open
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
19 changes: 18 additions & 1 deletion src/Analyser/MutatingScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -1043,7 +1043,24 @@
&& !$node instanceof Expr\ArrowFunction
&& $this->hasExpressionType($node)->yes()
) {
return $this->expressionTypes[$exprString]->getType();
$type = $this->expressionTypes[$exprString]->getType();

if ($node instanceof Expr\ArrayDimFetch && $node->dim !== null) {
$dimType = $this->getType($node->dim);
if ($dimType->isConstantScalarValue()->yes()) {

Check warning on line 1050 in src/Analyser/MutatingScope.php

View workflow job for this annotation

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

Escaped Mutant for Mutator "PHPStan\Infection\TrinaryLogicMutator": @@ @@ if ($node instanceof Expr\ArrayDimFetch && $node->dim !== null) { $dimType = $this->getType($node->dim); - if ($dimType->isConstantScalarValue()->yes()) { + if (!$dimType->isConstantScalarValue()->no()) { $arrayType = $this->getType($node->var); $offsetValueType = $arrayType->getOffsetValueType($dimType); if (

Check warning on line 1050 in src/Analyser/MutatingScope.php

View workflow job for this annotation

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

Escaped Mutant for Mutator "PHPStan\Infection\TrinaryLogicMutator": @@ @@ if ($node instanceof Expr\ArrayDimFetch && $node->dim !== null) { $dimType = $this->getType($node->dim); - if ($dimType->isConstantScalarValue()->yes()) { + if (!$dimType->isConstantScalarValue()->no()) { $arrayType = $this->getType($node->var); $offsetValueType = $arrayType->getOffsetValueType($dimType); if (
$arrayType = $this->getType($node->var);
$offsetValueType = $arrayType->getOffsetValueType($dimType);
if (
!$offsetValueType instanceof ErrorType
&& $type->isSuperTypeOf($offsetValueType)->yes()

Check warning on line 1055 in src/Analyser/MutatingScope.php

View workflow job for this annotation

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

Escaped Mutant for Mutator "PHPStan\Infection\TrinaryLogicMutator": @@ @@ $offsetValueType = $arrayType->getOffsetValueType($dimType); if ( !$offsetValueType instanceof ErrorType - && $type->isSuperTypeOf($offsetValueType)->yes() + && !$type->isSuperTypeOf($offsetValueType)->no() && !$offsetValueType->isSuperTypeOf($type)->yes() ) { $type = $offsetValueType;

Check warning on line 1055 in src/Analyser/MutatingScope.php

View workflow job for this annotation

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

Escaped Mutant for Mutator "PHPStan\Infection\TrinaryLogicMutator": @@ @@ $offsetValueType = $arrayType->getOffsetValueType($dimType); if ( !$offsetValueType instanceof ErrorType - && $type->isSuperTypeOf($offsetValueType)->yes() + && !$type->isSuperTypeOf($offsetValueType)->no() && !$offsetValueType->isSuperTypeOf($type)->yes() ) { $type = $offsetValueType;
&& !$offsetValueType->isSuperTypeOf($type)->yes()
) {
$type = $offsetValueType;
}
}
}

return $type;
}

/** @var ExprHandler<Expr> $exprHandler */
Expand Down
31 changes: 31 additions & 0 deletions tests/PHPStan/Analyser/nsrt/bug-11705.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php declare(strict_types = 1);

namespace Bug11705;

use function PHPStan\Testing\assertType;

/**
* @param array{'name':string,'owners':array<int,string>} $theInput
* @param array<int,string> $theTags
*/
function example(array $theInput, array $theTags): void
{
foreach ($theTags as $tag) {
if (!array_key_exists($tag, $theInput)) {
continue;
}
switch ($tag) {
case 'name':
assertType("'name'", $tag);
assertType('string', $theInput[$tag]);
if ($tag === 'name') {
echo "Of course it is...";
}
assertType("'name'", $tag);
assertType('string', $theInput[$tag]);
break;
default:
// fall out
}
}
}
Loading