mirror of
https://github.com/danog/psalm.git
synced 2024-12-02 17:52:45 +01:00
Fix #3910 - improve handling of fgetcsv
This commit is contained in:
parent
7ed5e32840
commit
ad1920c3a2
@ -225,6 +225,7 @@ C::foo("hello");
|
|||||||
### MissingPropertyType
|
### MissingPropertyType
|
||||||
|
|
||||||
Running `vendor/bin/psalter --issues=MissingPropertyType` on
|
Running `vendor/bin/psalter --issues=MissingPropertyType` on
|
||||||
|
|
||||||
```php
|
```php
|
||||||
<?php
|
<?php
|
||||||
class A {
|
class A {
|
||||||
|
@ -211,6 +211,29 @@ class FunctionAnalyzer extends FunctionLikeAnalyzer
|
|||||||
// Really this should only work on instances we've created with new Foo(),
|
// Really this should only work on instances we've created with new Foo(),
|
||||||
// but that requires more work
|
// but that requires more work
|
||||||
break;
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1304,6 +1304,14 @@ class FunctionCallTest extends TestCase
|
|||||||
|
|
||||||
safeMatch("/a/", "b");'
|
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));'
|
||||||
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user