Skip to content

Commit

Permalink
Fix fgetcsv return type; never returns null
Browse files Browse the repository at this point in the history
  • Loading branch information
janedbal authored Dec 5, 2024
1 parent 28dfac8 commit fbcad41
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions resources/functionMap_php80delta.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
'error_log' => ['bool', 'message'=>'string', 'message_type='=>'0|1|3|4', 'destination='=>'string', 'extra_headers='=>'string'],
'explode' => ['list<string>', 'separator'=>'non-empty-string', 'str'=>'string', 'limit='=>'int'],
'fdiv' => ['float', 'dividend'=>'float', 'divisor'=>'float'],
'fgetcsv' => ['list<string>|array{0: null}|false', 'fp'=>'resource', 'length='=>'0|positive-int|null', 'delimiter='=>'string', 'enclosure='=>'string', 'escape='=>'string'],
'filter_input' => ['mixed', 'type'=>'INPUT_GET|INPUT_POST|INPUT_COOKIE|INPUT_SERVER|INPUT_ENV', 'variable_name'=>'string', 'filter='=>'int', 'options='=>'array|int'],
'filter_input_array' => ['array|false|null', 'type'=>'INPUT_GET|INPUT_POST|INPUT_COOKIE|INPUT_SERVER|INPUT_ENV', 'definition='=>'int|array', 'add_empty='=>'bool'],
'floor' => ['float', 'number'=>'float'],
Expand Down
12 changes: 12 additions & 0 deletions tests/PHPStan/Analyser/nsrt/fgetcsv-php7.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php // lint < 8.0

declare(strict_types = 1);

namespace TestFGetCsvPhp7;

use function PHPStan\Testing\assertType;

function test($resource): void
{
assertType('list<string|null>|false|null', fgetcsv($resource)); // nullable when invalid argument is given (https://3v4l.org/4WmR5#v7.4.30)
}
12 changes: 12 additions & 0 deletions tests/PHPStan/Analyser/nsrt/fgetcsv-php8.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php // lint >= 8.0

declare(strict_types = 1);

namespace TestFGetCsvPhp8;

use function PHPStan\Testing\assertType;

function test($resource): void
{
assertType('list<string|null>|false', fgetcsv($resource));
}

0 comments on commit fbcad41

Please # to comment.