Skip to content

Commit de58f9a

Browse files
committed
CompactFunctionReturnTypeExtension - observe checkMaybeUndefinedVariables
1 parent f2dd33a commit de58f9a

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

conf/config.neon

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -900,6 +900,8 @@ services:
900900
class: PHPStan\Type\Php\CompactFunctionReturnTypeExtension
901901
tags:
902902
- phpstan.broker.dynamicFunctionReturnTypeExtension
903+
arguments:
904+
checkMaybeUndefinedVariables: %checkMaybeUndefinedVariables%
903905

904906
-
905907
class: PHPStan\Type\Php\CountFunctionReturnTypeExtension

src/Type/Php/CompactFunctionReturnTypeExtension.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@
1515
class CompactFunctionReturnTypeExtension implements DynamicFunctionReturnTypeExtension
1616
{
1717

18+
private bool $checkMaybeUndefinedVariables;
19+
20+
public function __construct(bool $checkMaybeUndefinedVariables)
21+
{
22+
$this->checkMaybeUndefinedVariables = $checkMaybeUndefinedVariables;
23+
}
24+
1825
public function isFunctionSupported(FunctionReflection $functionReflection): bool
1926
{
2027
return $functionReflection->getName() === 'compact';
@@ -31,7 +38,7 @@ public function getTypeFromFunctionCall(
3138
return $defaultReturnType;
3239
}
3340

34-
if ($scope->canAnyVariableExist()) {
41+
if ($scope->canAnyVariableExist() && !$this->checkMaybeUndefinedVariables) {
3542
return $defaultReturnType;
3643
}
3744

0 commit comments

Comments
 (0)