Skip to content
Merged
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
32 changes: 21 additions & 11 deletions src/Analyser/MutatingScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -4453,9 +4453,10 @@
{
if ($typeWithMethod instanceof UnionType) {
$typeWithMethod = $typeWithMethod->filterTypes(static fn (Type $innerType) => $innerType->hasMethod($methodName)->yes());
}

if (!$typeWithMethod->hasMethod($methodName)->yes()) {

@staabm staabm Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

before this PR:

in case of a UnionType, this if-condition invoked ->hasMethod($methodName)->yes() again on a UnionType, which previously was filtered with ->filterTypes(static fn (Type $innerType) => $innerType->hasMethod($methodName)->yes()) - so could either contain only types which have the method $methodName, or a NeverType.

if ($typeWithMethod instanceof NeverType) {
return null;
}
} elseif (!$typeWithMethod->hasMethod($methodName)->yes()) {
return null;
}

Expand Down Expand Up @@ -4491,8 +4492,10 @@
{
if ($typeWithProperty instanceof UnionType) {
$typeWithProperty = $typeWithProperty->filterTypes(static fn (Type $innerType) => $innerType->hasProperty($propertyName)->yes());
}
if (!$typeWithProperty->hasProperty($propertyName)->yes()) {
if ($typeWithProperty instanceof NeverType) {
return null;
}
} elseif (!$typeWithProperty->hasProperty($propertyName)->yes()) {
return null;
}

Expand All @@ -4504,8 +4507,10 @@
{
if ($typeWithProperty instanceof UnionType) {
$typeWithProperty = $typeWithProperty->filterTypes(static fn (Type $innerType) => $innerType->hasInstanceProperty($propertyName)->yes());
}
if (!$typeWithProperty->hasInstanceProperty($propertyName)->yes()) {
if ($typeWithProperty instanceof NeverType) {
return null;
}
} elseif (!$typeWithProperty->hasInstanceProperty($propertyName)->yes()) {

Check warning on line 4513 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": @@ @@ if ($typeWithProperty instanceof NeverType) { return null; } - } elseif (!$typeWithProperty->hasInstanceProperty($propertyName)->yes()) { + } elseif ($typeWithProperty->hasInstanceProperty($propertyName)->no()) { return null; }

Check warning on line 4513 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": @@ @@ if ($typeWithProperty instanceof NeverType) { return null; } - } elseif (!$typeWithProperty->hasInstanceProperty($propertyName)->yes()) { + } elseif ($typeWithProperty->hasInstanceProperty($propertyName)->no()) { return null; }
return null;
}

Expand All @@ -4517,8 +4522,10 @@
{
if ($typeWithProperty instanceof UnionType) {
$typeWithProperty = $typeWithProperty->filterTypes(static fn (Type $innerType) => $innerType->hasStaticProperty($propertyName)->yes());
}
if (!$typeWithProperty->hasStaticProperty($propertyName)->yes()) {
if ($typeWithProperty instanceof NeverType) {
return null;
}
} elseif (!$typeWithProperty->hasStaticProperty($propertyName)->yes()) {
return null;
}

Expand All @@ -4529,8 +4536,11 @@
{
if ($typeWithConstant instanceof UnionType) {
$typeWithConstant = $typeWithConstant->filterTypes(static fn (Type $innerType) => $innerType->hasConstant($constantName)->yes());
}
if (!$typeWithConstant->hasConstant($constantName)->yes()) {

if ($typeWithConstant instanceof NeverType) {
return null;
}
} elseif (!$typeWithConstant->hasConstant($constantName)->yes()) {
return null;
}

Expand Down
Loading