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

$inputIsArray = $inputType->isArray();
$hasRequireArrayFlag = $this->hasFlag('FILTER_REQUIRE_ARRAY', $flagsType);
$hasThrowOnFailureFlag = $this->hasFlag('FILTER_THROW_ON_FAILURE', $flagsType);
if ($inputIsArray->no() && $hasRequireArrayFlag->yes()) {
if ($this->hasFlag('FILTER_THROW_ON_FAILURE', $flagsType)->yes()) {
if ($hasThrowOnFailureFlag->yes()) {

Check warning on line 156 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": @@ @@ $hasRequireArrayFlag = $this->hasFlag('FILTER_REQUIRE_ARRAY', $flagsType); $hasThrowOnFailureFlag = $this->hasFlag('FILTER_THROW_ON_FAILURE', $flagsType); if ($inputIsArray->no() && $hasRequireArrayFlag->yes()) { - if ($hasThrowOnFailureFlag->yes()) { + if (!$hasThrowOnFailureFlag->no()) { return new ErrorType(); }

Check warning on line 156 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": @@ @@ $hasRequireArrayFlag = $this->hasFlag('FILTER_REQUIRE_ARRAY', $flagsType); $hasThrowOnFailureFlag = $this->hasFlag('FILTER_THROW_ON_FAILURE', $flagsType); if ($inputIsArray->no() && $hasRequireArrayFlag->yes()) { - if ($hasThrowOnFailureFlag->yes()) { + if (!$hasThrowOnFailureFlag->no()) { return new ErrorType(); }
return new ErrorType();
}

Expand Down Expand Up @@ -197,9 +198,13 @@
}
}

if ($hasThrowOnFailureFlag->yes()) {

Check warning on line 201 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": @@ @@ } } - if ($hasThrowOnFailureFlag->yes()) { + if (!$hasThrowOnFailureFlag->no()) { $type = TypeCombinator::remove($type, $defaultType); }

Check warning on line 201 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": @@ @@ } } - if ($hasThrowOnFailureFlag->yes()) { + if (!$hasThrowOnFailureFlag->no()) { $type = TypeCombinator::remove($type, $defaultType); }
$type = TypeCombinator::remove($type, $defaultType);
}

if ($hasRequireArrayFlag->yes()) {
$type = new ArrayType($inputArrayKeyType ?? $mixedType, $type);
if (!$inputIsArray->yes()) {
if (!$hasThrowOnFailureFlag->yes() && !$inputIsArray->yes()) {

Check warning on line 207 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": @@ @@ if ($hasRequireArrayFlag->yes()) { $type = new ArrayType($inputArrayKeyType ?? $mixedType, $type); - if (!$hasThrowOnFailureFlag->yes() && !$inputIsArray->yes()) { + if ($hasThrowOnFailureFlag->no() && !$inputIsArray->yes()) { $type = TypeCombinator::union($type, $defaultType); } }

Check warning on line 207 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": @@ @@ if ($hasRequireArrayFlag->yes()) { $type = new ArrayType($inputArrayKeyType ?? $mixedType, $type); - if (!$hasThrowOnFailureFlag->yes() && !$inputIsArray->yes()) { + if ($hasThrowOnFailureFlag->no() && !$inputIsArray->yes()) { $type = TypeCombinator::union($type, $defaultType); } }
$type = TypeCombinator::union($type, $defaultType);
}
}
Expand All @@ -208,10 +213,6 @@
return new ArrayType($inputArrayKeyType ?? $mixedType, $type);
}

if ($this->hasFlag('FILTER_THROW_ON_FAILURE', $flagsType)->yes()) {
$type = TypeCombinator::remove($type, $defaultType);
}

return $type;
}

Expand Down
6 changes: 6 additions & 0 deletions tests/PHPStan/Analyser/nsrt/filter-var-php85.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,10 @@ public function doFoo($mixed): void
assertType('int', filter_var($mixed, FILTER_VALIDATE_INT, FILTER_THROW_ON_FAILURE));
assertType('int', filter_var($mixed, FILTER_VALIDATE_INT, ['flags' => FILTER_THROW_ON_FAILURE]));
}

public function more($mixed): void
{
assertType('array<int>', filter_var($mixed, FILTER_VALIDATE_INT, FILTER_FORCE_ARRAY|FILTER_THROW_ON_FAILURE));
assertType('array<int>', filter_var($mixed, FILTER_VALIDATE_INT, FILTER_REQUIRE_ARRAY|FILTER_THROW_ON_FAILURE));
}
}
Loading