diff --git a/src/Analyser/DirectScopeFactory.php b/src/Analyser/DirectScopeFactory.php index cc2b90c983..91bac134b6 100644 --- a/src/Analyser/DirectScopeFactory.php +++ b/src/Analyser/DirectScopeFactory.php @@ -13,7 +13,6 @@ use PHPStan\Reflection\ReflectionProvider; use PHPStan\Rules\Properties\PropertyReflectionFinder; use PHPStan\ShouldNotHappenException; -use PHPStan\Type\Type; use function is_a; /** @@ -45,7 +44,6 @@ public function __construct( } /** - * @param array $constantTypes * @param ExpressionTypeHolder[] $expressionTypes * @param array $conditionalExpressions * @param array $currentlyAssignedExpressions @@ -57,7 +55,6 @@ public function __construct( public function create( ScopeContext $context, bool $declareStrictTypes = false, - array $constantTypes = [], FunctionReflection|MethodReflection|null $function = null, ?string $namespace = null, array $expressionTypes = [], @@ -93,7 +90,6 @@ public function create( $context, $this->phpVersion, $declareStrictTypes, - $constantTypes, $function, $namespace, $expressionTypes, diff --git a/src/Analyser/LazyScopeFactory.php b/src/Analyser/LazyScopeFactory.php index 7832e02eef..168f1f16b1 100644 --- a/src/Analyser/LazyScopeFactory.php +++ b/src/Analyser/LazyScopeFactory.php @@ -13,7 +13,6 @@ use PHPStan\Reflection\ReflectionProvider; use PHPStan\Rules\Properties\PropertyReflectionFinder; use PHPStan\ShouldNotHappenException; -use PHPStan\Type\Type; use function is_a; class LazyScopeFactory implements ScopeFactory @@ -39,7 +38,6 @@ public function __construct( } /** - * @param array $constantTypes * @param ExpressionTypeHolder[] $expressionTypes * @param array $conditionalExpressions * @param array $currentlyAssignedExpressions @@ -51,7 +49,6 @@ public function __construct( public function create( ScopeContext $context, bool $declareStrictTypes = false, - array $constantTypes = [], FunctionReflection|MethodReflection|null $function = null, ?string $namespace = null, array $expressionTypes = [], @@ -87,7 +84,6 @@ public function create( $context, $this->container->getByType(PhpVersion::class), $declareStrictTypes, - $constantTypes, $function, $namespace, $expressionTypes, diff --git a/src/Analyser/MutatingScope.php b/src/Analyser/MutatingScope.php index 39e8c4cd40..18b76ebdca 100644 --- a/src/Analyser/MutatingScope.php +++ b/src/Analyser/MutatingScope.php @@ -119,6 +119,7 @@ use function array_key_exists; use function array_keys; use function array_map; +use function array_merge; use function array_pop; use function array_slice; use function count; @@ -155,7 +156,6 @@ class MutatingScope implements Scope private ?self $scopeOutOfFirstLevelStatement = null; /** - * @param array $constantTypes * @param ExpressionTypeHolder[] $expressionTypes * @param array $conditionalExpressions * @param array $currentlyAssignedExpressions @@ -177,7 +177,6 @@ public function __construct( private ScopeContext $context, private PhpVersion $phpVersion, private bool $declareStrictTypes = false, - private array $constantTypes = [], private FunctionReflection|ExtendedMethodReflection|null $function = null, ?string $namespace = null, private array $expressionTypes = [], @@ -248,7 +247,6 @@ public function enterDeclareStrictTypes(): self return $this->scopeFactory->create( $this->context, true, - [], null, null, $this->expressionTypes, @@ -317,7 +315,6 @@ public function afterExtractCall(): self return $this->scopeFactory->create( $this->context, $this->isDeclareStrictTypes(), - $this->constantTypes, $this->getFunction(), $this->getNamespace(), $this->expressionTypes, @@ -373,7 +370,6 @@ public function afterClearstatcacheCall(): self return $this->scopeFactory->create( $this->context, $this->isDeclareStrictTypes(), - $this->constantTypes, $this->getFunction(), $this->getNamespace(), $expressionTypes, @@ -455,7 +451,6 @@ public function afterOpenSslCall(string $openSslFunctionName): self return $this->scopeFactory->create( $this->context, $this->isDeclareStrictTypes(), - $this->constantTypes, $this->getFunction(), $this->getNamespace(), $expressionTypes, @@ -565,21 +560,13 @@ public function hasConstant(Name $name): bool if ($isCompilerHaltOffset) { return $this->fileHasCompilerHaltStatementCalls(); } - if ($name->isFullyQualified()) { - if (array_key_exists($name->toCodeString(), $this->constantTypes)) { - return true; - } - } - if ($this->getNamespace() !== null) { - $constantName = new FullyQualified([$this->getNamespace(), $name->toString()]); - if (array_key_exists($constantName->toCodeString(), $this->constantTypes)) { + if (!$name->isFullyQualified() && $this->getNamespace() !== null) { + if ($this->hasExpressionType(new ConstFetch(new FullyQualified([$this->getNamespace(), $name->toString()])))->yes()) { return true; } } - - $constantName = new FullyQualified($name->toString()); - if (array_key_exists($constantName->toCodeString(), $this->constantTypes)) { + if ($this->hasExpressionType(new ConstFetch(new FullyQualified($name->toString())))->yes()) { return true; } @@ -1652,22 +1639,23 @@ private function resolveType(Expr $node): Type return new NullType(); } - if ($node->name->isFullyQualified()) { - if (array_key_exists($node->name->toCodeString(), $this->constantTypes)) { - return $this->constantResolver->resolveConstantType($node->name->toString(), $this->constantTypes[$node->name->toCodeString()]); - } + $namespacedName = null; + if (!$node->name->isFullyQualified() && $this->getNamespace() !== null) { + $namespacedName = new FullyQualified([$this->getNamespace(), $node->name->toString()]); } + $globalName = new FullyQualified($node->name->toString()); - if ($this->getNamespace() !== null) { - $constantName = new FullyQualified([$this->getNamespace(), $constName]); - if (array_key_exists($constantName->toCodeString(), $this->constantTypes)) { - return $this->constantResolver->resolveConstantType($constantName->toString(), $this->constantTypes[$constantName->toCodeString()]); + foreach ([$namespacedName, $globalName] as $name) { + if ($name === null) { + continue; + } + $constFetch = new ConstFetch($name); + if ($this->hasExpressionType($constFetch)->yes()) { + return $this->constantResolver->resolveConstantType( + $name->toString(), + $this->expressionTypes[$this->getNodeKey($constFetch)]->getType(), + ); } - } - - $constantName = new FullyQualified($constName); - if (array_key_exists($constantName->toCodeString(), $this->constantTypes)) { - return $this->constantResolver->resolveConstantType($constantName->toString(), $this->constantTypes[$constantName->toCodeString()]); } $constantType = $this->constantResolver->resolveConstant($node->name, $this); @@ -2173,7 +2161,6 @@ public function doNotTreatPhpDocTypesAsCertain(): Scope $this->context, $this->phpVersion, $this->declareStrictTypes, - $this->constantTypes, $this->function, $this->namespace, $this->expressionTypes, @@ -2213,7 +2200,6 @@ private function promoteNativeTypes(): self return $this->scopeFactory->create( $this->context, $this->declareStrictTypes, - $this->constantTypes, $this->function, $this->namespace, $expressionTypes, @@ -2395,7 +2381,6 @@ public function pushInFunctionCall($reflection): self $scope = $this->scopeFactory->create( $this->context, $this->isDeclareStrictTypes(), - $this->constantTypes, $this->getFunction(), $this->getNamespace(), $this->expressionTypes, @@ -2425,7 +2410,6 @@ public function popInFunctionCall(): self $scope = $this->scopeFactory->create( $this->context, $this->isDeclareStrictTypes(), - $this->constantTypes, $this->getFunction(), $this->getNamespace(), $this->expressionTypes, @@ -2486,12 +2470,11 @@ public function enterClass(ClassReflection $classReflection): self return $this->scopeFactory->create( $this->context->enterClass($classReflection), $this->isDeclareStrictTypes(), - $this->constantTypes, null, $this->getNamespace(), - [ + array_merge($this->getConstantTypes(), [ '$this' => ExpressionTypeHolder::createYes(new ThisType($classReflection)), - ], + ]), [], null, null, @@ -2518,7 +2501,6 @@ public function enterTrait(ClassReflection $traitReflection): self return $this->scopeFactory->create( $this->context->enterTrait($traitReflection), $this->isDeclareStrictTypes(), - $this->constantTypes, $this->getFunction(), $namespace, $this->expressionTypes, @@ -2727,10 +2709,9 @@ private function enterFunctionLike( return $this->scopeFactory->create( $this->context, $this->isDeclareStrictTypes(), - $this->constantTypes, $functionReflection, $this->getNamespace(), - $expressionTypes, + array_merge($this->getConstantTypes(), $expressionTypes), [], null, null, @@ -2746,7 +2727,6 @@ public function enterNamespace(string $namespaceName): self return $this->scopeFactory->create( $this->context->beginFile(), $this->isDeclareStrictTypes(), - $this->constantTypes, null, $namespaceName, ); @@ -2768,7 +2748,6 @@ public function enterClosureBind(?Type $thisType, string $scopeClass): self return $this->scopeFactory->create( $this->context, $this->isDeclareStrictTypes(), - $this->constantTypes, $this->getFunction(), $this->getNamespace(), $expressionTypes, @@ -2790,7 +2769,6 @@ public function restoreOriginalScopeAfterClosureBind(self $originalScope): self return $this->scopeFactory->create( $this->context, $this->isDeclareStrictTypes(), - $this->constantTypes, $this->getFunction(), $this->getNamespace(), $expressionTypes, @@ -2808,7 +2786,6 @@ public function enterClosureCall(Type $thisType): self return $this->scopeFactory->create( $this->context, $this->isDeclareStrictTypes(), - $this->constantTypes, $this->getFunction(), $this->getNamespace(), $expressionTypes, @@ -2843,7 +2820,6 @@ public function enterAnonymousFunction( return $this->scopeFactory->create( $scope->context, $scope->isDeclareStrictTypes(), - $scope->constantTypes, $scope->getFunction(), $scope->getNamespace(), $scope->expressionTypes, @@ -2953,10 +2929,9 @@ private function enterAnonymousFunctionWithoutReflection( return $this->scopeFactory->create( $this->context, $this->isDeclareStrictTypes(), - $this->constantTypes, $this->getFunction(), $this->getNamespace(), - $expressionTypes, + array_merge($this->getConstantTypes(), $expressionTypes), [], $this->inClosureBindScopeClass, new TrivialParametersAcceptor(), @@ -2986,7 +2961,6 @@ public function enterArrowFunction(Expr\ArrowFunction $arrowFunction, ?array $ca return $this->scopeFactory->create( $scope->context, $scope->isDeclareStrictTypes(), - $scope->constantTypes, $scope->getFunction(), $scope->getNamespace(), $scope->expressionTypes, @@ -3045,7 +3019,6 @@ private function enterArrowFunctionWithoutReflection(Expr\ArrowFunction $arrowFu return $this->scopeFactory->create( $arrowFunctionScope->context, $this->isDeclareStrictTypes(), - $arrowFunctionScope->constantTypes, $arrowFunctionScope->getFunction(), $arrowFunctionScope->getNamespace(), $arrowFunctionScope->expressionTypes, @@ -3175,7 +3148,6 @@ public function enterExpressionAssign(Expr $expr): self $scope = $this->scopeFactory->create( $this->context, $this->isDeclareStrictTypes(), - $this->constantTypes, $this->getFunction(), $this->getNamespace(), $this->expressionTypes, @@ -3206,7 +3178,6 @@ public function exitExpressionAssign(Expr $expr): self $scope = $this->scopeFactory->create( $this->context, $this->isDeclareStrictTypes(), - $this->constantTypes, $this->getFunction(), $this->getNamespace(), $this->expressionTypes, @@ -3248,7 +3219,6 @@ public function setAllowedUndefinedExpression(Expr $expr): self $scope = $this->scopeFactory->create( $this->context, $this->isDeclareStrictTypes(), - $this->constantTypes, $this->getFunction(), $this->getNamespace(), $this->expressionTypes, @@ -3279,7 +3249,6 @@ public function unsetAllowedUndefinedExpression(Expr $expr): self $scope = $this->scopeFactory->create( $this->context, $this->isDeclareStrictTypes(), - $this->constantTypes, $this->getFunction(), $this->getNamespace(), $this->expressionTypes, @@ -3342,7 +3311,6 @@ public function assignVariable(string $variableName, Type $type, Type $nativeTyp return $this->scopeFactory->create( $this->context, $this->isDeclareStrictTypes(), - $this->constantTypes, $this->getFunction(), $this->getNamespace(), $expressionTypes, @@ -3377,7 +3345,6 @@ public function unsetExpression(Expr $expr): self return $this->scopeFactory->create( $this->context, $this->isDeclareStrictTypes(), - $this->constantTypes, $this->getFunction(), $this->getNamespace(), $expressionTypes, @@ -3431,40 +3398,19 @@ private function specifyExpressionType(Expr $expr, Type $type, Type $nativeType) return $this; } + $exprString = $this->getNodeKey($expr); if ($expr instanceof ConstFetch) { - $constantTypes = $this->constantTypes; - $constantName = new FullyQualified($expr->name->toString()); - + $loweredConstName = strtolower($expr->name->toString()); + if (in_array($loweredConstName, ['true', 'false', 'null'], true)) { + return $this; + } if ($type instanceof NeverType) { - unset($constantTypes[$constantName->toCodeString()]); - } else { - $constantTypes[$constantName->toCodeString()] = $type; + unset($this->expressionTypes[$exprString]); + return $this; } - - return $this->scopeFactory->create( - $this->context, - $this->isDeclareStrictTypes(), - $constantTypes, - $this->getFunction(), - $this->getNamespace(), - $this->expressionTypes, - $this->conditionalExpressions, - $this->inClosureBindScopeClass, - $this->anonymousFunctionReflection, - $this->inFirstLevelStatement, - $this->currentlyAssignedExpressions, - $this->currentlyAllowedUndefinedExpressions, - $this->nativeExpressionTypes, - $this->inFunctionCallsStack, - $this->afterExtractCall, - $this->parentScope, - ); } - $exprString = $this->getNodeKey($expr); - $scope = $this; - if ($expr instanceof Variable && is_string($expr->name)) { $variableName = $expr->name; $exprString = '$' . $variableName; @@ -3523,7 +3469,6 @@ private function specifyExpressionType(Expr $expr, Type $type, Type $nativeType) return $this->scopeFactory->create( $this->context, $this->isDeclareStrictTypes(), - $this->constantTypes, $this->getFunction(), $this->getNamespace(), $expressionTypes, @@ -3646,7 +3591,6 @@ public function invalidateExpression(Expr $expressionToInvalidate, bool $require return $this->scopeFactory->create( $this->context, $this->isDeclareStrictTypes(), - $this->constantTypes, $this->getFunction(), $this->getNamespace(), $expressionTypes, @@ -3713,7 +3657,6 @@ private function invalidateMethodsOnExpression(Expr $expressionToInvalidate): se return $this->scopeFactory->create( $this->context, $this->isDeclareStrictTypes(), - $this->constantTypes, $this->getFunction(), $this->getNamespace(), $expressionTypes, @@ -3938,7 +3881,6 @@ public function changeConditionalExpressions(array $newConditionalExpressionHold return $this->scopeFactory->create( $this->context, $this->isDeclareStrictTypes(), - $this->constantTypes, $this->getFunction(), $this->getNamespace(), $this->expressionTypes, @@ -3965,7 +3907,6 @@ public function addConditionalExpressions(string $exprString, array $conditional return $this->scopeFactory->create( $this->context, $this->isDeclareStrictTypes(), - $this->constantTypes, $this->getFunction(), $this->getNamespace(), $this->expressionTypes, @@ -3995,7 +3936,6 @@ public function exitFirstLevelStatements(): self $scope = $this->scopeFactory->create( $this->context, $this->isDeclareStrictTypes(), - $this->constantTypes, $this->getFunction(), $this->getNamespace(), $this->expressionTypes, @@ -4038,7 +3978,6 @@ private function addMoreSpecificTypes(array $types): self return $this->scopeFactory->create( $this->context, $this->isDeclareStrictTypes(), - $this->constantTypes, $this->getFunction(), $this->getNamespace(), $expressionTypes, @@ -4060,12 +3999,6 @@ public function mergeWith(?self $otherScope): self if ($otherScope === null) { return $this; } - - $variableHolderToType = static fn (ExpressionTypeHolder $holder): Type => $holder->getType(); - $typeToVariableHolder = static fn (Type $type): ExpressionTypeHolder => new ExpressionTypeHolder($type, TrinaryLogic::createYes()); - - $filterVariableHolders = static fn (ExpressionTypeHolder $holder): bool => $holder->getCertainty()->yes(); - $ourExpressionTypes = $this->expressionTypes; $ourVariableTypes = array_filter($ourExpressionTypes, fn ($exprString) => $this->exprStringToExpr((string) $exprString) instanceof Variable, ARRAY_FILTER_USE_KEY); $theirExpressionTypes = $otherScope->expressionTypes; @@ -4108,10 +4041,6 @@ public function mergeWith(?self $otherScope): self return $this->scopeFactory->create( $this->context, $this->isDeclareStrictTypes(), - array_map($variableHolderToType, array_filter($this->mergeVariableHolders( - array_map($typeToVariableHolder, $this->constantTypes), - array_map($typeToVariableHolder, $otherScope->constantTypes), - ), $filterVariableHolders)), $this->getFunction(), $this->getNamespace(), $mergedExpressionTypes, @@ -4259,18 +4188,9 @@ private function mergeVariableHolders(array $ourVariableTypeHolders, array $thei public function processFinallyScope(self $finallyScope, self $originalFinallyScope): self { - $variableHolderToType = static fn (ExpressionTypeHolder $holder): Type => $holder->getType(); - $typeToVariableHolder = static fn (Type $type): ExpressionTypeHolder => new ExpressionTypeHolder($type, TrinaryLogic::createYes()); - $filterVariableHolders = static fn (ExpressionTypeHolder $holder): bool => $holder->getCertainty()->yes(); - return $this->scopeFactory->create( $this->context, $this->isDeclareStrictTypes(), - array_map($variableHolderToType, array_filter($this->processFinallyScopeVariableTypeHolders( - array_map($typeToVariableHolder, $this->constantTypes), - array_map($typeToVariableHolder, $finallyScope->constantTypes), - array_map($typeToVariableHolder, $originalFinallyScope->constantTypes), - ), $filterVariableHolders)), $this->getFunction(), $this->getNamespace(), $this->processFinallyScopeVariableTypeHolders( @@ -4372,7 +4292,6 @@ public function processClosureScope( return $this->scopeFactory->create( $this->context, $this->isDeclareStrictTypes(), - $this->constantTypes, $this->getFunction(), $this->getNamespace(), $expressionTypes, @@ -4419,7 +4338,6 @@ public function processAlwaysIterableForeachScopeWithoutPollute(self $finalScope return $this->scopeFactory->create( $this->context, $this->isDeclareStrictTypes(), - $this->constantTypes, $this->getFunction(), $this->getNamespace(), $expressionTypes, @@ -4447,17 +4365,9 @@ public function generalizeWith(self $otherScope): self $otherScope->nativeExpressionTypes, ); - $variableHolderToType = static fn (ExpressionTypeHolder $holder): Type => $holder->getType(); - $typeToVariableHolder = static fn (Type $type): ExpressionTypeHolder => new ExpressionTypeHolder($type, TrinaryLogic::createYes()); - $filterVariableHolders = static fn (ExpressionTypeHolder $holder): bool => $holder->getCertainty()->yes(); - return $this->scopeFactory->create( $this->context, $this->isDeclareStrictTypes(), - array_map($variableHolderToType, array_filter($this->generalizeVariableTypeHolders( - array_map($typeToVariableHolder, $this->constantTypes), - array_map($typeToVariableHolder, $otherScope->constantTypes), - ), $filterVariableHolders)), $this->getFunction(), $this->getNamespace(), $variableTypeHolders, @@ -4827,18 +4737,7 @@ public function equals(self $otherScope): bool if (!$this->compareVariableTypeHolders($this->expressionTypes, $otherScope->expressionTypes)) { return false; } - - $typeToVariableHolder = static fn (Type $type): ExpressionTypeHolder => new ExpressionTypeHolder($type, TrinaryLogic::createYes()); - - $nativeExpressionTypesResult = $this->compareVariableTypeHolders($this->nativeExpressionTypes, $otherScope->nativeExpressionTypes); - if (!$nativeExpressionTypesResult) { - return false; - } - - return $this->compareVariableTypeHolders( - array_map($typeToVariableHolder, $this->constantTypes), - array_map($typeToVariableHolder, $otherScope->constantTypes), - ); + return $this->compareVariableTypeHolders($this->nativeExpressionTypes, $otherScope->nativeExpressionTypes); } /** @@ -4932,10 +4831,6 @@ public function debug(): array $key = sprintf('%s (%s)', $name, $variableTypeHolder->getCertainty()->describe()); $descriptions[$key] = $variableTypeHolder->getType()->describe(VerbosityLevel::precise()); } - foreach ($this->constantTypes as $name => $type) { - $key = sprintf('const %s', $name); - $descriptions[$key] = $type->describe(VerbosityLevel::precise()); - } foreach ($this->nativeExpressionTypes as $exprString => $nativeTypeHolder) { $key = sprintf('native %s', $exprString); $descriptions[$key] = $nativeTypeHolder->getType()->describe(VerbosityLevel::precise()); @@ -5264,4 +5159,20 @@ public function getConstantReflection(Type $typeWithConstant, string $constantNa return $typeWithConstant->getConstant($constantName); } + /** + * @return ExpressionTypeHolder[] + */ + private function getConstantTypes(): array + { + $constantTypes = []; + foreach ($this->expressionTypes as $exprString => $typeHolder) { + $expr = $this->exprStringToExpr((string) $exprString); + if (!$expr instanceof ConstFetch) { + continue; + } + $constantTypes[$exprString] = $typeHolder; + } + return $constantTypes; + } + } diff --git a/src/Analyser/NodeScopeResolver.php b/src/Analyser/NodeScopeResolver.php index 1f7c3e26d2..11d7afef07 100644 --- a/src/Analyser/NodeScopeResolver.php +++ b/src/Analyser/NodeScopeResolver.php @@ -1445,12 +1445,12 @@ private function processStmtNode( foreach ($stmt->consts as $const) { $nodeCallback($const, $scope); $this->processExprNode($const->value, $scope, $nodeCallback, ExpressionContext::createDeep()); - if ($scope->getNamespace() !== null) { - $constName = [$scope->getNamespace(), $const->name->toString()]; + if ($const->namespacedName !== null) { + $constantName = new Name\FullyQualified($const->namespacedName->toString()); } else { - $constName = $const->name->toString(); + $constantName = new Name\FullyQualified($const->name->toString()); } - $scope = $scope->assignExpression(new ConstFetch(new Name\FullyQualified($constName)), $scope->getType($const->value), $scope->getNativeType($const->value)); + $scope = $scope->assignExpression(new ConstFetch($constantName), $scope->getType($const->value), $scope->getNativeType($const->value)); } } elseif ($stmt instanceof Node\Stmt\Nop) { $scope = $this->processStmtVarAnnotation($scope, $stmt, null); diff --git a/src/Analyser/ScopeFactory.php b/src/Analyser/ScopeFactory.php index 3cc8cd534a..080cc82d98 100644 --- a/src/Analyser/ScopeFactory.php +++ b/src/Analyser/ScopeFactory.php @@ -5,14 +5,12 @@ use PHPStan\Reflection\FunctionReflection; use PHPStan\Reflection\MethodReflection; use PHPStan\Reflection\ParametersAcceptor; -use PHPStan\Type\Type; interface ScopeFactory { /** * @api - * @param array $constantTypes * @param ExpressionTypeHolder[] $expressionTypes * @param array $conditionalExpressions * @param array $currentlyAssignedExpressions @@ -24,7 +22,6 @@ interface ScopeFactory public function create( ScopeContext $context, bool $declareStrictTypes = false, - array $constantTypes = [], FunctionReflection|MethodReflection|null $function = null, ?string $namespace = null, array $expressionTypes = [], diff --git a/src/Reflection/Php/PhpClassReflectionExtension.php b/src/Reflection/Php/PhpClassReflectionExtension.php index f7ab2e78bf..17ff6871b8 100644 --- a/src/Reflection/Php/PhpClassReflectionExtension.php +++ b/src/Reflection/Php/PhpClassReflectionExtension.php @@ -945,7 +945,6 @@ private function inferAndCachePropertyTypes( $classScope = $this->scopeFactory->create( ScopeContext::create($fileName), false, - [], $constructor, $namespace, )->enterClass($declaringClass); diff --git a/tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php b/tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php index caf935f0b3..94f7084dab 100644 --- a/tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php +++ b/tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php @@ -8381,7 +8381,7 @@ public function dataDynamicConstants(): array 'DynamicConstants\NoDynamicConstantClass::DYNAMIC_CONSTANT_IN_CLASS', ], [ - 'bool', + 'false', 'GLOBAL_DYNAMIC_CONSTANT', ], [ diff --git a/tests/PHPStan/Analyser/data/bug-4434.php b/tests/PHPStan/Analyser/data/bug-4434.php index 7e0b97d7fb..a1f3bea048 100644 --- a/tests/PHPStan/Analyser/data/bug-4434.php +++ b/tests/PHPStan/Analyser/data/bug-4434.php @@ -13,8 +13,8 @@ public function testSendEmailToLog(): void assertType('int<5, max>', PHP_MAJOR_VERSION); assertType('int<5, max>', \PHP_MAJOR_VERSION); if (PHP_MAJOR_VERSION === 7) { - assertType('int', PHP_MAJOR_VERSION); - assertType('int', \PHP_MAJOR_VERSION); + assertType('7', PHP_MAJOR_VERSION); + assertType('7', \PHP_MAJOR_VERSION); } else { assertType('int<5, 6>|int<8, max>', PHP_MAJOR_VERSION); assertType('int<5, 6>|int<8, max>', \PHP_MAJOR_VERSION); @@ -31,8 +31,8 @@ public function testSendEmailToLog(): void assertType('int<5, max>', PHP_MAJOR_VERSION); assertType('int<5, max>', \PHP_MAJOR_VERSION); if (PHP_MAJOR_VERSION === 100) { - assertType('int', PHP_MAJOR_VERSION); - assertType('int', \PHP_MAJOR_VERSION); + assertType('100', PHP_MAJOR_VERSION); + assertType('100', \PHP_MAJOR_VERSION); } else { assertType('int<5, 99>|int<101, max>', PHP_MAJOR_VERSION); assertType('int<5, 99>|int<101, max>', \PHP_MAJOR_VERSION);