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
10 changes: 7 additions & 3 deletions src/Type/Php/FilterFunctionReturnTypeHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -517,9 +517,13 @@

private function hasThrowOnFailureFlag(?Type $flagsType, PhpVersions $phpVersions): TrinaryLogic
{
return $phpVersions->hasFilterThrowOnFailureConstant()->no()
? TrinaryLogic::createNo()
: $this->hasFlag('FILTER_THROW_ON_FAILURE', $flagsType);
$hasThrowOnFailureConstant = $phpVersions->hasFilterThrowOnFailureConstant();
if ($hasThrowOnFailureConstant->no()) {

Check warning on line 521 in src/Type/Php/FilterFunctionReturnTypeHelper.php

View workflow job for this annotation

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

Escaped Mutant for Mutator "PHPStan\Infection\TrinaryLogicMutator": @@ @@ private function hasThrowOnFailureFlag(?Type $flagsType, PhpVersions $phpVersions): TrinaryLogic { $hasThrowOnFailureConstant = $phpVersions->hasFilterThrowOnFailureConstant(); - if ($hasThrowOnFailureConstant->no()) { + if (!$hasThrowOnFailureConstant->yes()) { return TrinaryLogic::createNo(); }

Check warning on line 521 in src/Type/Php/FilterFunctionReturnTypeHelper.php

View workflow job for this annotation

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

Escaped Mutant for Mutator "PHPStan\Infection\TrinaryLogicMutator": @@ @@ private function hasThrowOnFailureFlag(?Type $flagsType, PhpVersions $phpVersions): TrinaryLogic { $hasThrowOnFailureConstant = $phpVersions->hasFilterThrowOnFailureConstant(); - if ($hasThrowOnFailureConstant->no()) { + if (!$hasThrowOnFailureConstant->yes()) { return TrinaryLogic::createNo(); }
return TrinaryLogic::createNo();
}

// before PHP 8.5, this bit is FILTER_FLAG_GLOBAL_RANGE and the failure value is still returned
return $hasThrowOnFailureConstant->and($this->hasFlag('FILTER_THROW_ON_FAILURE', $flagsType));
}

private function getFlagsValue(Type $exprType): Type
Expand Down
36 changes: 36 additions & 0 deletions tests/PHPStan/Analyser/Bug15481Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php declare(strict_types = 1);

namespace PHPStan\Analyser;

use PHPStan\Testing\TypeInferenceTestCase;
use PHPUnit\Framework\Attributes\DataProvider;

class Bug15481Test extends TypeInferenceTestCase
{

public static function dataFileAsserts(): iterable
{
yield from self::gatherAssertTypes(__DIR__ . '/data/bug-15481.php');
}

/**
* @param mixed ...$args
*/
#[DataProvider('dataFileAsserts')]
public function testFileAsserts(
string $assertType,
string $file,
...$args,
): void
{
$this->assertFileAsserts($assertType, $file, ...$args);
}

public static function getAdditionalConfigFiles(): array
{
return [
__DIR__ . '/bug-15481.neon',
];
}

}
4 changes: 4 additions & 0 deletions tests/PHPStan/Analyser/bug-15481.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
parameters:
phpVersion:
min: 80400
max: 80599
18 changes: 18 additions & 0 deletions tests/PHPStan/Analyser/data/bug-15481.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php declare(strict_types = 1);

namespace Bug15481;

use function PHPStan\Testing\assertType;

function isPublicAddress(string $address): bool
{
assertType('non-falsy-string|false', filter_var($address, FILTER_VALIDATE_IP, FILTER_FLAG_GLOBAL_RANGE));
assertType('non-falsy-string|false', filter_var($address, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE | FILTER_FLAG_GLOBAL_RANGE));

return filter_var($address, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE | FILTER_FLAG_GLOBAL_RANGE) !== false;
}

function throwOnFailure(string $s): void
{
assertType('int|false', filter_var($s, FILTER_VALIDATE_INT, FILTER_THROW_ON_FAILURE));
}
Loading