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

if (array_key_exists($exprString, $theirExpressionTypes)) {
$ourType = $holder->getType();
$theirType = $theirExpressionTypes[$exprString]->getType();
$isSuperType = $ourType->isSuperTypeOf($theirType);

Check warning on line 3586 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": @@ @@ if (array_key_exists($exprString, $theirExpressionTypes)) { $ourType = $holder->getType(); $theirType = $theirExpressionTypes[$exprString]->getType(); - $isSuperType = $ourType->isSuperTypeOf($theirType); + $isSuperType = $theirType->isSuperTypeOf($ourType); if ( $isSuperType->yes() || ($isSuperType->maybe() && !($ourType->isObject()->yes() && $theirType->isObject()->yes()))

Check warning on line 3586 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": @@ @@ if (array_key_exists($exprString, $theirExpressionTypes)) { $ourType = $holder->getType(); $theirType = $theirExpressionTypes[$exprString]->getType(); - $isSuperType = $ourType->isSuperTypeOf($theirType); + $isSuperType = $theirType->isSuperTypeOf($ourType); if ( $isSuperType->yes() || ($isSuperType->maybe() && !($ourType->isObject()->yes() && $theirType->isObject()->yes()))
if (
$isSuperType->yes()
|| ($isSuperType->maybe() && !($ourType->isObject()->yes() && $theirType->isObject()->yes()))

Check warning on line 3589 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": @@ @@ $isSuperType = $ourType->isSuperTypeOf($theirType); if ( $isSuperType->yes() - || ($isSuperType->maybe() && !($ourType->isObject()->yes() && $theirType->isObject()->yes())) + || ($isSuperType->maybe() && !($ourType->isObject()->yes() && !$theirType->isObject()->no())) ) { continue; }

Check warning on line 3589 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": @@ @@ $isSuperType = $ourType->isSuperTypeOf($theirType); if ( $isSuperType->yes() - || ($isSuperType->maybe() && !($ourType->isObject()->yes() && $theirType->isObject()->yes())) + || ($isSuperType->maybe() && !(!$ourType->isObject()->no() && $theirType->isObject()->yes())) ) { continue; }

Check warning on line 3589 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": @@ @@ $isSuperType = $ourType->isSuperTypeOf($theirType); if ( $isSuperType->yes() - || ($isSuperType->maybe() && !($ourType->isObject()->yes() && $theirType->isObject()->yes())) + || ($isSuperType->maybe() && !($ourType->isObject()->yes() && !$theirType->isObject()->no())) ) { continue; }

Check warning on line 3589 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": @@ @@ $isSuperType = $ourType->isSuperTypeOf($theirType); if ( $isSuperType->yes() - || ($isSuperType->maybe() && !($ourType->isObject()->yes() && $theirType->isObject()->yes())) + || ($isSuperType->maybe() && !(!$ourType->isObject()->no() && $theirType->isObject()->yes())) ) { continue; }
) {
continue;
}
}

$typeGuards[$exprString] = $holder;
}

Expand Down
6 changes: 6 additions & 0 deletions tests/PHPStan/Analyser/AnalyserIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1506,6 +1506,12 @@ public function testBug13801(): void
$this->assertNoErrors($errors);
}

public function testSyliusOrderIpListener(): void
{
$errors = $this->runAnalyse(__DIR__ . '/data/sylius-order-ip-listener.php');
$this->assertNoErrors($errors);
}

/**
* @param string[]|null $allAnalysedFiles
* @return list<Error>
Expand Down
30 changes: 30 additions & 0 deletions tests/PHPStan/Analyser/data/sylius-order-ip-listener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php // lint >= 8.0

declare(strict_types = 1);

namespace SyliusOrderIpListenerIntegration;

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;
}

return $order;
}
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);
}
}
25 changes: 25 additions & 0 deletions tests/PHPStan/Analyser/nsrt/bug-10843.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php // lint >= 8.0

declare(strict_types = 1);

namespace Bug10843;

use function PHPStan\Testing\assertType;

class HelloWorld
{
public function sayHello(HelloWorld|null $date): int
{
$a = match (true) {
$date instanceof HelloWorld => 1,
default => false
};

if ($date instanceof HelloWorld) {
assertType('1|false', $a);
return $a;
}

throw new \Exception('Error');
}
}
33 changes: 33 additions & 0 deletions tests/PHPStan/Analyser/nsrt/bug-11328.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?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);
}

assertType('DateTimeImmutable|null', $fromDeadline);

if (in_array(Status::Expired, $statuses, true)) {
assertType('DateTimeImmutable|null', $fromDeadline);
if ($fromDeadline === null) {
$toDeadline = (new \DateTimeImmutable())->setTime(0, 0, 0);
} else {
$fromDeadline = null;
}
}
}
28 changes: 28 additions & 0 deletions tests/PHPStan/Analyser/nsrt/bug-14211.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types = 1);

namespace Bug14211;

use function PHPStan\Testing\assertType;

/** @param array<mixed> $data */
function doSomething(array $data): bool
{
if (!isset($data['x'])) {
return false;
}

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

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

if ($m) {
assertType('true', $m);
}

return true;
}
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