Skip to content

Commit

Permalink
Correct the return type of SplFileObject::fstat()
Browse files Browse the repository at this point in the history
  • Loading branch information
johnbillion committed Feb 6, 2022
1 parent 30798b5 commit c0fe972
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion resources/functionMap.php
Expand Up @@ -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'],
Expand Down
4 changes: 2 additions & 2 deletions src/Type/Php/StatDynamicReturnTypeExtension.php
Expand Up @@ -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
Expand Down Expand Up @@ -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();
}

}
4 changes: 4 additions & 0 deletions tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php
Expand Up @@ -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',
Expand Down
2 changes: 2 additions & 0 deletions tests/PHPStan/Analyser/data/functions.php
Expand Up @@ -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);
Expand Down

0 comments on commit c0fe972

Please sign in to comment.