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

foreach ($variableTypeGuards as $guardExprString => $guardHolder) {
if (
array_key_exists($exprString, $theirExpressionTypes)
&& $theirExpressionTypes[$exprString]->getCertainty()->yes()

Check warning on line 3608 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": @@ @@ foreach ($variableTypeGuards as $guardExprString => $guardHolder) { if ( array_key_exists($exprString, $theirExpressionTypes) - && $theirExpressionTypes[$exprString]->getCertainty()->yes() + && !$theirExpressionTypes[$exprString]->getCertainty()->no() && array_key_exists($guardExprString, $theirExpressionTypes) && $theirExpressionTypes[$guardExprString]->getCertainty()->yes() && !$guardHolder->getType()->isSuperTypeOf($theirExpressionTypes[$guardExprString]->getType())->no()

Check warning on line 3608 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": @@ @@ foreach ($variableTypeGuards as $guardExprString => $guardHolder) { if ( array_key_exists($exprString, $theirExpressionTypes) - && $theirExpressionTypes[$exprString]->getCertainty()->yes() + && !$theirExpressionTypes[$exprString]->getCertainty()->no() && array_key_exists($guardExprString, $theirExpressionTypes) && $theirExpressionTypes[$guardExprString]->getCertainty()->yes() && !$guardHolder->getType()->isSuperTypeOf($theirExpressionTypes[$guardExprString]->getType())->no()
&& array_key_exists($guardExprString, $theirExpressionTypes)
&& $theirExpressionTypes[$guardExprString]->getCertainty()->yes()

Check warning on line 3610 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": @@ @@ array_key_exists($exprString, $theirExpressionTypes) && $theirExpressionTypes[$exprString]->getCertainty()->yes() && array_key_exists($guardExprString, $theirExpressionTypes) - && $theirExpressionTypes[$guardExprString]->getCertainty()->yes() + && !$theirExpressionTypes[$guardExprString]->getCertainty()->no() && !$guardHolder->getType()->isSuperTypeOf($theirExpressionTypes[$guardExprString]->getType())->no() ) { continue;

Check warning on line 3610 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": @@ @@ array_key_exists($exprString, $theirExpressionTypes) && $theirExpressionTypes[$exprString]->getCertainty()->yes() && array_key_exists($guardExprString, $theirExpressionTypes) - && $theirExpressionTypes[$guardExprString]->getCertainty()->yes() + && !$theirExpressionTypes[$guardExprString]->getCertainty()->no() && !$guardHolder->getType()->isSuperTypeOf($theirExpressionTypes[$guardExprString]->getType())->no() ) { continue;
&& !$guardHolder->getType()->isSuperTypeOf($theirExpressionTypes[$guardExprString]->getType())->no()

Check warning on line 3611 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\IsSuperTypeOfCalleeAndArgumentMutator": @@ @@ && $theirExpressionTypes[$exprString]->getCertainty()->yes() && array_key_exists($guardExprString, $theirExpressionTypes) && $theirExpressionTypes[$guardExprString]->getCertainty()->yes() - && !$guardHolder->getType()->isSuperTypeOf($theirExpressionTypes[$guardExprString]->getType())->no() + && !$theirExpressionTypes[$guardExprString]->getType()->isSuperTypeOf($guardHolder->getType())->no() ) { continue; }

Check warning on line 3611 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\IsSuperTypeOfCalleeAndArgumentMutator": @@ @@ && $theirExpressionTypes[$exprString]->getCertainty()->yes() && array_key_exists($guardExprString, $theirExpressionTypes) && $theirExpressionTypes[$guardExprString]->getCertainty()->yes() - && !$guardHolder->getType()->isSuperTypeOf($theirExpressionTypes[$guardExprString]->getType())->no() + && !$theirExpressionTypes[$guardExprString]->getType()->isSuperTypeOf($guardHolder->getType())->no() ) { continue; }
) {
continue;
}
$conditionalExpression = new ConditionalExpressionHolder([$guardExprString => $guardHolder], $holder);
$conditionalExpressions[$exprString][$conditionalExpression->getKey()] = $conditionalExpression;
}
Expand Down
28 changes: 28 additions & 0 deletions tests/PHPStan/Analyser/nsrt/bug-10085.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types = 1);

namespace Bug10085;

use function PHPStan\Testing\assertType;

class HelloWorld
{
/**
* @param array<int, string> $foo
* @param list<string> $bar
*/
public function sayHello(array $foo, array $bar): void
{
$a = $foo;
if ($a === []) {
$a = $bar;
}

if ($a === []) {
return;
}

assertType('array<int, string>', $foo);
}
}
27 changes: 27 additions & 0 deletions tests/PHPStan/Analyser/nsrt/bug-11328.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php // lint >= 8.1

declare(strict_types = 1);

namespace Bug11328;

use function PHPStan\Testing\assertType;

enum Status: string {
case Live = 's1';
case Expired = 's2';
}

/** @param Status[] $statuses */
function check(array $statuses): void {
$fromDeadline = null;
$toDeadline = null;
if (in_array(Status::Live, $statuses, true)) {
$fromDeadline = (new \DateTimeImmutable())->setTime(23, 59, 59);
}
if (in_array(Status::Expired, $statuses, true)) {
assertType('DateTimeImmutable|null', $fromDeadline);
if ($fromDeadline === null) {
$toDeadline = (new \DateTimeImmutable())->setTime(0, 0, 0);
}
}
}
27 changes: 27 additions & 0 deletions tests/PHPStan/Analyser/nsrt/bug-14211.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php // lint >= 8.0

declare(strict_types = 1);

namespace Bug14211;

use function PHPStan\Testing\assertType;

/** @param array<mixed> $data */
function DoSomithing(array $data): bool {

if (!isset($data['x']))
return false;

$m = isset($data['y']);

if ($m) {
assertType('true', $m); // ok: true
}
assertType('bool', $m); // ok: bool

if ($m) {
assertType('true', $m); // <-- should not be: NEVER
}

return true;
}
36 changes: 36 additions & 0 deletions tests/PHPStan/Analyser/nsrt/bug-14411-regression.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php // lint >= 8.0

declare(strict_types = 1);

namespace Bug14411Regression;

use function PHPStan\Testing\assertType;
use function PHPStan\Testing\assertVariableCertainty;
use PHPStan\TrinaryLogic;

interface OrderInterface {}

class Event
{
/** @return mixed */
public function getSubject()
{
return new \stdClass();
}
}

function getOrder(Event|OrderInterface $event): OrderInterface
{
if ($event instanceof Event) {
$order = $event->getSubject();
assert($order instanceof OrderInterface);
}

if ($event instanceof OrderInterface) {
$order = $event;
}

assertVariableCertainty(TrinaryLogic::createYes(), $order);

return $order;
}
34 changes: 34 additions & 0 deletions tests/PHPStan/Analyser/nsrt/bug-14411.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php // lint >= 8.0

declare(strict_types = 1);

namespace Bug14411;

use function PHPStan\Testing\assertType;

/** @phpstan-impure */
function get_mixed(): mixed {
return random_int(0, 1) ? 'foo' : null;
}

/** @phpstan-impure */
function get_optional_int(): ?int {
return random_int(0, 1) ? 42 : null;
}

function (): void {
$a = get_mixed();

if ($a !== null) {
$b = $a;
}
else {
$b = get_optional_int();
}
if ($b !== null) {
assertType('mixed', $a);
if ($a === null) {
echo 'this is absolutely possible';
}
}
};
Loading