diff --git a/src/Type/Nette/ComponentGetPresenterDynamicReturnTypeExtension.php b/src/Type/Nette/ComponentGetPresenterDynamicReturnTypeExtension.php index 83d090c..0b3d89c 100644 --- a/src/Type/Nette/ComponentGetPresenterDynamicReturnTypeExtension.php +++ b/src/Type/Nette/ComponentGetPresenterDynamicReturnTypeExtension.php @@ -6,7 +6,6 @@ use PHPStan\Analyser\Scope; use PHPStan\Reflection\MethodReflection; use PHPStan\Reflection\ParametersAcceptorSelector; -use PHPStan\Type\Constant\ConstantBooleanType; use PHPStan\Type\DynamicMethodReturnTypeExtension; use PHPStan\Type\Type; use PHPStan\Type\TypeCombinator; @@ -44,11 +43,10 @@ public function getTypeFromMethodCall(MethodReflection $methodReflection, Method $paramNeedExpr = $methodCall->getArgs()[0]->value; $paramNeedType = $scope->getType($paramNeedExpr); - if ($paramNeedType instanceof ConstantBooleanType) { - if ($paramNeedType->getValue()) { - return TypeCombinator::removeNull($defaultReturnType); - } - + if ($paramNeedType->isTrue()->yes()) { + return TypeCombinator::removeNull($defaultReturnType); + } + if ($paramNeedType->isFalse()->yes()) { return TypeCombinator::addNull($defaultReturnType); } diff --git a/src/Type/Nette/ComponentLookupDynamicReturnTypeExtension.php b/src/Type/Nette/ComponentLookupDynamicReturnTypeExtension.php index 371ae56..658ab7e 100644 --- a/src/Type/Nette/ComponentLookupDynamicReturnTypeExtension.php +++ b/src/Type/Nette/ComponentLookupDynamicReturnTypeExtension.php @@ -6,7 +6,6 @@ use PHPStan\Analyser\Scope; use PHPStan\Reflection\MethodReflection; use PHPStan\Reflection\ParametersAcceptorSelector; -use PHPStan\Type\Constant\ConstantBooleanType; use PHPStan\Type\DynamicMethodReturnTypeExtension; use PHPStan\Type\Type; use PHPStan\Type\TypeCombinator; @@ -37,11 +36,10 @@ public function getTypeFromMethodCall(MethodReflection $methodReflection, Method $paramNeedExpr = $methodCall->getArgs()[1]->value; $paramNeedType = $scope->getType($paramNeedExpr); - if ($paramNeedType instanceof ConstantBooleanType) { - if ($paramNeedType->getValue()) { - return TypeCombinator::removeNull($defaultReturnType); - } - + if ($paramNeedType->isTrue()->yes()) { + return TypeCombinator::removeNull($defaultReturnType); + } + if ($paramNeedType->isFalse()->yes()) { return TypeCombinator::addNull($defaultReturnType); } diff --git a/src/Type/Nette/FormContainerValuesDynamicReturnTypeExtension.php b/src/Type/Nette/FormContainerValuesDynamicReturnTypeExtension.php index a757f84..d4bf152 100644 --- a/src/Type/Nette/FormContainerValuesDynamicReturnTypeExtension.php +++ b/src/Type/Nette/FormContainerValuesDynamicReturnTypeExtension.php @@ -5,9 +5,7 @@ use PhpParser\Node\Expr\MethodCall; use PHPStan\Analyser\Scope; use PHPStan\Reflection\MethodReflection; -use PHPStan\Reflection\ParametersAcceptorSelector; use PHPStan\Type\ArrayType; -use PHPStan\Type\Constant\ConstantBooleanType; use PHPStan\Type\DynamicMethodReturnTypeExtension; use PHPStan\Type\MixedType; use PHPStan\Type\ObjectType; @@ -28,7 +26,7 @@ public function isMethodSupported(MethodReflection $methodReflection): bool return $methodReflection->getName() === 'getValues'; } - public function getTypeFromMethodCall(MethodReflection $methodReflection, MethodCall $methodCall, Scope $scope): Type + public function getTypeFromMethodCall(MethodReflection $methodReflection, MethodCall $methodCall, Scope $scope): ?Type { if (count($methodCall->getArgs()) === 0) { return new ObjectType('Nette\Utils\ArrayHash'); @@ -36,15 +34,14 @@ public function getTypeFromMethodCall(MethodReflection $methodReflection, Method $arg = $methodCall->getArgs()[0]->value; $scopedType = $scope->getType($arg); - if (!$scopedType instanceof ConstantBooleanType) { - return ParametersAcceptorSelector::selectSingle($methodReflection->getVariants())->getReturnType(); + if ($scopedType->isTrue()->yes()) { + return new ArrayType(new StringType(), new MixedType()); } - - if (!$scopedType->getValue()) { + if ($scopedType->isFalse()->yes()) { return new ObjectType('Nette\Utils\ArrayHash'); } - return new ArrayType(new StringType(), new MixedType()); + return null; } } diff --git a/src/Type/Nette/ServiceLocatorDynamicReturnTypeExtension.php b/src/Type/Nette/ServiceLocatorDynamicReturnTypeExtension.php index 84c0449..d485b6f 100644 --- a/src/Type/Nette/ServiceLocatorDynamicReturnTypeExtension.php +++ b/src/Type/Nette/ServiceLocatorDynamicReturnTypeExtension.php @@ -5,7 +5,6 @@ use PhpParser\Node\Expr\MethodCall; use PHPStan\Analyser\Scope; use PHPStan\Reflection\MethodReflection; -use PHPStan\Type\Constant\ConstantBooleanType; use PHPStan\Type\DynamicMethodReturnTypeExtension; use PHPStan\Type\MixedType; use PHPStan\Type\ObjectType; @@ -57,10 +56,7 @@ public function getTypeFromMethodCall(MethodReflection $methodReflection, Method && count($methodCall->getArgs()) >= 2 ) { $throwType = $scope->getType($methodCall->getArgs()[1]->value); - if ( - !$throwType instanceof ConstantBooleanType - || !$throwType->getValue() - ) { + if (!$throwType->isTrue()->yes()) { $type = TypeCombinator::addNull($type); } }