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
16 changes: 16 additions & 0 deletions src/Analyser/ExprHandler/FuncCallHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
use PHPStan\Reflection\ParametersAcceptor;
use PHPStan\Reflection\ParametersAcceptorSelector;
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Rules\Comparison\ImpossibleCheckTypeHelper;
use PHPStan\TrinaryLogic;
use PHPStan\Type\Accessory\AccessoryArrayListType;
use PHPStan\Type\Accessory\HasPropertyType;
Expand All @@ -56,6 +57,7 @@
use PHPStan\Type\ClosureType;
use PHPStan\Type\Constant\ConstantArrayType;
use PHPStan\Type\Constant\ConstantArrayTypeBuilder;
use PHPStan\Type\Constant\ConstantBooleanType;
use PHPStan\Type\DynamicFunctionThrowTypeExtension;
use PHPStan\Type\DynamicReturnTypeExtensionRegistry;
use PHPStan\Type\ErrorType;
Expand Down Expand Up @@ -107,6 +109,7 @@ public function __construct(
#[AutowiredParameter]
private bool $rememberPossiblyImpureFunctionValues,
private ExpressionResultFactory $expressionResultFactory,
private ImpossibleCheckTypeHelper $impossibleCheckTypeHelper,
)
{
}
Expand Down Expand Up @@ -1053,6 +1056,19 @@ private function getDynamicFunctionReturnType(MutatingScope $scope, FuncCall $no
}
}

// for always-true/always-false type checks the call's own narrowing
// decides the return type - the verdict reads the same specified types
// the check contributes when used as a condition
if (
$normalizedNode->name instanceof Name
&& in_array($normalizedNode->name->toLowerString(), ['array_key_exists', 'key_exists', 'in_array', 'is_subclass_of'], true)
) {
$isAlways = $this->impossibleCheckTypeHelper->findSpecifiedType($scope, $normalizedNode);
if ($isAlways !== null) {
return new ConstantBooleanType($isAlways);
}
}

return null;
}

Expand Down
77 changes: 0 additions & 77 deletions src/Type/Php/TypeSpecifyingFunctionsDynamicReturnTypeExtension.php

This file was deleted.

Loading