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
15 changes: 14 additions & 1 deletion src/Analyser/ExpressionTypeHolder.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
final class ExpressionTypeHolder
{

public function __construct(private Expr $expr, private Type $type, private TrinaryLogic $certainty)
public function __construct(
private readonly Expr $expr,
private readonly Type $type,
private readonly TrinaryLogic $certainty,
)
{
}

Expand All @@ -24,6 +28,15 @@ public static function createMaybe(Expr $expr, Type $type): self
return new self($expr, $type, TrinaryLogic::createMaybe());
}

public function equalTypes(self $other): bool
{
if ($this === $other) {
return true;
}

return $this->type === $other->type || $this->type->equals($other->type);
}

public function equals(self $other): bool
{
if ($this === $other) {
Expand Down
12 changes: 6 additions & 6 deletions src/Analyser/MutatingScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -4014,7 +4014,7 @@
continue;
}

if (!$mergedExpressionTypes[$exprString]->getType()->equals($holder->getType())) {
if (!$mergedExpressionTypes[$exprString]->equalTypes($holder)) {
continue;
}

Expand All @@ -4023,13 +4023,13 @@

$typeGuards = [];
foreach ($newVariableTypes as $exprString => $holder) {
if (!$holder->getCertainty()->yes()) {
if (!array_key_exists($exprString, $mergedExpressionTypes)) {
continue;
}
if (!array_key_exists($exprString, $mergedExpressionTypes)) {
if (!$holder->getCertainty()->yes()) {

Check warning on line 4029 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 (!array_key_exists($exprString, $mergedExpressionTypes)) { continue; } - if (!$holder->getCertainty()->yes()) { + if ($holder->getCertainty()->no()) { continue; } if ($mergedExpressionTypes[$exprString]->equalTypes($holder)) {

Check warning on line 4029 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 (!array_key_exists($exprString, $mergedExpressionTypes)) { continue; } - if (!$holder->getCertainty()->yes()) { + if ($holder->getCertainty()->no()) { continue; } if ($mergedExpressionTypes[$exprString]->equalTypes($holder)) {
continue;
}
if ($mergedExpressionTypes[$exprString]->getType()->equals($holder->getType())) {
if ($mergedExpressionTypes[$exprString]->equalTypes($holder)) {
continue;
}

Expand Down Expand Up @@ -4194,7 +4194,7 @@
foreach ($finallyVariableTypeHolders as $exprString => $variableTypeHolder) {
if (
isset($originalVariableTypeHolders[$exprString])
&& !$originalVariableTypeHolders[$exprString]->getType()->equals($variableTypeHolder->getType())
&& !$originalVariableTypeHolders[$exprString]->equalTypes($variableTypeHolder)
) {
$ourVariableTypeHolders[$exprString] = $variableTypeHolder;
continue;
Expand Down Expand Up @@ -4766,7 +4766,7 @@
return false;
}

if (!$variableTypeHolder->getType()->equals($otherVariableTypeHolders[$variableExprString]->getType())) {
if (!$variableTypeHolder->equalTypes($otherVariableTypeHolders[$variableExprString])) {
return false;
}
}
Expand Down
Loading