1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Fix #3910 - improve handling of fgetcsv

This commit is contained in:
Brown 2020-07-30 14:21:42 -04:00
parent 7ed5e32840
commit ad1920c3a2
3 changed files with 32 additions and 0 deletions

View File

@ -225,6 +225,7 @@ C::foo("hello");
### MissingPropertyType
Running `vendor/bin/psalter --issues=MissingPropertyType` on
```php
<?php
class A {

View File

@ -211,6 +211,29 @@ class FunctionAnalyzer extends FunctionLikeAnalyzer
// Really this should only work on instances we've created with new Foo(),
// but that requires more work
break;
case 'fgetcsv':
$string_type = Type::getString();
$string_type->addType(new Type\Atomic\TNull);
$string_type->ignore_nullable_issues = true;
$call_map_return_type = new Type\Union([
new Type\Atomic\TNonEmptyList(
$string_type
),
new Type\Atomic\TFalse,
new Type\Atomic\TNull
]);
if ($codebase->config->ignore_internal_nullable_issues) {
$call_map_return_type->ignore_nullable_issues = true;
}
if ($codebase->config->ignore_internal_falsable_issues) {
$call_map_return_type->ignore_falsable_issues = true;
}
return $call_map_return_type;
}
}

View File

@ -1304,6 +1304,14 @@ class FunctionCallTest extends TestCase
safeMatch("/a/", "b");'
],
'fgetcsv' => [
'<?php
$headers = fgetcsv(fopen("test.txt", "r"));
if (empty($headers)) {
throw new Exception("invalid headers");
}
print_r(array_map("strval", $headers));'
],
];
}