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: 7 additions & 0 deletions src/Analyser/MutatingScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -3298,6 +3298,7 @@
}

$conditions = [];
$originallySpecifiedExprStrings = $specifiedExpressions;
$prevSpecifiedCount = -1;
while (count($specifiedExpressions) !== $prevSpecifiedCount) {
$prevSpecifiedCount = count($specifiedExpressions);
Expand All @@ -3308,6 +3309,12 @@

// Pass 1: Prefer exact matches
foreach ($conditionalExpressions as $conditionalExpression) {
if (
$conditionalExpression->getTypeHolder()->getCertainty()->no()

Check warning on line 3313 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": @@ @@ // Pass 1: Prefer exact matches foreach ($conditionalExpressions as $conditionalExpression) { if ( - $conditionalExpression->getTypeHolder()->getCertainty()->no() + !$conditionalExpression->getTypeHolder()->getCertainty()->yes() && array_key_exists($conditionalExprString, $originallySpecifiedExprStrings) ) { continue;

Check warning on line 3313 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": @@ @@ // Pass 1: Prefer exact matches foreach ($conditionalExpressions as $conditionalExpression) { if ( - $conditionalExpression->getTypeHolder()->getCertainty()->no() + !$conditionalExpression->getTypeHolder()->getCertainty()->yes() && array_key_exists($conditionalExprString, $originallySpecifiedExprStrings) ) { continue;
&& array_key_exists($conditionalExprString, $originallySpecifiedExprStrings)
) {
continue;
}
foreach ($conditionalExpression->getConditionExpressionTypeHolders() as $holderExprString => $conditionalTypeHolder) {
if (
!array_key_exists($holderExprString, $specifiedExpressions)
Expand Down
111 changes: 111 additions & 0 deletions tests/PHPStan/Analyser/nsrt/bug-14645.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<?php

namespace Bug14645;

use function PHPStan\Testing\assertType;

final class C
{
public function __construct(private ?self $a, private ?self $b)
{
}

public function check(): bool
{
if ($this->a !== null && $this->b !== null) {
throw new \LogicException();
}

if ($this->a !== null) {
$this->a->check();
}

if ($this->b !== null) {
assertType('Bug14645\C', $this->b);
$this->b->check();
}

return true;
}
}

final class VariableAnalog
{
public function test(?\stdClass $a, ?\stdClass $b): void
{
if ($a !== null && $b !== null) {
throw new \LogicException();
}

if ($a !== null) {
echo $a->foo;
}

if ($b !== null) {
assertType('stdClass', $b);
echo $b->bar;
}
}
}

final class ReversedOrder
{
public function __construct(private ?self $a, private ?self $b)
{
}

public function check(): bool
{
if ($this->a !== null && $this->b !== null) {
throw new \LogicException();
}

if ($this->b !== null) {
$this->b->check();
}

if ($this->a !== null) {
assertType('Bug14645\ReversedOrder', $this->a);
$this->a->check();
}

return true;
}
}

final class ThreeProperties
{
public function __construct(
private ?self $a,
private ?self $b,
private ?self $c,
) {
}

public function check(): bool
{
if ($this->a !== null && $this->b !== null) {
throw new \LogicException();
}

if ($this->a !== null && $this->c !== null) {
throw new \LogicException();
}

if ($this->a !== null) {
$this->a->check();
}

if ($this->b !== null) {
assertType('Bug14645\ThreeProperties', $this->b);
$this->b->check();
}

if ($this->c !== null) {
assertType('Bug14645\ThreeProperties', $this->c);
$this->c->check();
}

return true;
}
}
Loading