diff --git a/resources/functionMap.php b/resources/functionMap.php index b9e5853900..955cf303ab 100644 --- a/resources/functionMap.php +++ b/resources/functionMap.php @@ -11294,7 +11294,7 @@ 'SplFileObject::fread' => ['string|false', 'length'=>'int'], 'SplFileObject::fscanf' => ['bool', 'format'=>'string', '&...w_vars='=>'string|int|float'], 'SplFileObject::fseek' => ['int', 'pos'=>'int', 'whence='=>'int'], -'SplFileObject::fstat' => ['array|false'], +'SplFileObject::fstat' => ['array'], 'SplFileObject::ftell' => ['int|false'], 'SplFileObject::ftruncate' => ['bool', 'size'=>'int'], 'SplFileObject::fwrite' => ['int', 'str'=>'string', 'length='=>'int'], diff --git a/src/Type/Php/StatDynamicReturnTypeExtension.php b/src/Type/Php/StatDynamicReturnTypeExtension.php index 3936541d45..7b8c08f194 100644 --- a/src/Type/Php/StatDynamicReturnTypeExtension.php +++ b/src/Type/Php/StatDynamicReturnTypeExtension.php @@ -28,7 +28,7 @@ public function isFunctionSupported(FunctionReflection $functionReflection): boo public function getTypeFromFunctionCall(FunctionReflection $functionReflection, FuncCall $functionCall, Scope $scope): Type { - return $this->getReturnType(); + return TypeCombinator::union($this->getReturnType(), new ConstantBooleanType(false)); } public function getClass(): string @@ -74,7 +74,7 @@ private function getReturnType(): Type $builder->setOffsetValueType(new ConstantStringType($key), $valueType); } - return TypeCombinator::union($builder->getArray(), new ConstantBooleanType(false)); + return $builder->getArray(); } } diff --git a/tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php b/tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php index 92bdde96ae..6f79bcd96c 100644 --- a/tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php +++ b/tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php @@ -5562,6 +5562,10 @@ public function dataFunctions(): array 'array{0: int, 1: int, 2: int, 3: int, 4: int, 5: int, 6: int, 7: int, 8: int, 9: int, 10: int, 11: int, 12: int, dev: int, ino: int, mode: int, nlink: int, uid: int, gid: int, rdev: int, size: int, atime: int, mtime: int, ctime: int, blksize: int, blocks: int}|false', '$fstat', ], + [ + 'array{0: int, 1: int, 2: int, 3: int, 4: int, 5: int, 6: int, 7: int, 8: int, 9: int, 10: int, 11: int, 12: int, dev: int, ino: int, mode: int, nlink: int, uid: int, gid: int, rdev: int, size: int, atime: int, mtime: int, ctime: int, blksize: int, blocks: int}', + '$fileObjectStat', + ], [ 'string', '$base64DecodeWithoutStrict', diff --git a/tests/PHPStan/Analyser/data/functions.php b/tests/PHPStan/Analyser/data/functions.php index 7c36d6e854..c71633634b 100644 --- a/tests/PHPStan/Analyser/data/functions.php +++ b/tests/PHPStan/Analyser/data/functions.php @@ -101,6 +101,8 @@ $stat = stat(__FILE__); $lstat = lstat(__FILE__); $fstat = fstat($resource); +$fileObject = new \SplFileObject(__FILE__); +$fileObjectStat = $fileObject->fstat(); $base64DecodeWithoutStrict = base64_decode(''); $base64DecodeWithStrictDisabled = base64_decode('', false);