Skip to content

Commit aeca670

Browse files
authored
Merge pull request #318 from Jean85/fix-fputcsv
Fix fputcsv annotation
2 parents 418777f + 74d8991 commit aeca670

File tree

3 files changed

+43
-34
lines changed

3 files changed

+43
-34
lines changed

generated/filesystem.php

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -895,40 +895,6 @@ function fopen(string $filename, string $mode, bool $use_include_path = false, $
895895
}
896896

897897

898-
/**
899-
* fputcsv formats a line (passed as a
900-
* fields array) as CSV and writes it (terminated by a
901-
* newline) to the specified file stream.
902-
*
903-
* @param resource $stream The file pointer must be valid, and must point to
904-
* a file successfully opened by fopen or
905-
* fsockopen (and not yet closed by
906-
* fclose).
907-
* @param array $fields An array of strings.
908-
* @param string $separator The optional separator parameter sets the field
909-
* delimiter (one single-byte character only).
910-
* @param string $enclosure The optional enclosure parameter sets the field
911-
* enclosure (one single-byte character only).
912-
* @param string $escape The optional escape parameter sets the
913-
* escape character (at most one single-byte character).
914-
* An empty string ("") disables the proprietary escape mechanism.
915-
* @param string $eol The optional eol parameter sets
916-
* a custom End of Line sequence.
917-
* @return int Returns the length of the written string.
918-
* @throws FilesystemException
919-
*
920-
*/
921-
function fputcsv($stream, array $fields, string $separator = ",", string $enclosure = "\"", string $escape = "\\", string $eol = "\n"): int
922-
{
923-
error_clear_last();
924-
$result = \fputcsv($stream, $fields, $separator, $enclosure, $escape, $eol);
925-
if ($result === false) {
926-
throw FilesystemException::createFromPhpError();
927-
}
928-
return $result;
929-
}
930-
931-
932898
/**
933899
* fread reads up to
934900
* length bytes from the file pointer

generator/config/specialCasesFunctions.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
'json_decode',
88
'apc_fetch',
99
'apcu_fetch',
10+
'fputcsv',
1011
'preg_replace',
1112
'openssl_encrypt',
1213
'readdir',

lib/special_cases.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace Safe;
99

10+
use Safe\Exceptions\FilesystemException;
1011
use const PREG_NO_ERROR;
1112

1213
use Safe\Exceptions\MiscException;
@@ -363,3 +364,44 @@ function posix_getpgid(int $process_id): int
363364
}
364365
return $result;
365366
}
367+
368+
369+
/**
370+
* fputcsv formats a line (passed as a
371+
* fields array) as CSV and writes it (terminated by a
372+
* newline) to the specified file stream.
373+
*
374+
* @param resource $stream The file pointer must be valid, and must point to
375+
* a file successfully opened by fopen or
376+
* fsockopen (and not yet closed by
377+
* fclose).
378+
* @phpstan-param (scalar|\Stringable|null)[] $fields
379+
* @param array $fields An array of strings.
380+
* @param string $separator The optional separator parameter sets the field
381+
* delimiter (one single-byte character only).
382+
* @param string $enclosure The optional enclosure parameter sets the field
383+
* enclosure (one single-byte character only).
384+
* @param string $escape The optional escape parameter sets the
385+
* escape character (at most one single-byte character).
386+
* An empty string ("") disables the proprietary escape mechanism.
387+
* @param string $eol The optional eol parameter sets
388+
* a custom End of Line sequence.
389+
* @return int Returns the length of the written string.
390+
* @throws FilesystemException
391+
*
392+
*/
393+
function fputcsv($stream, array $fields, string $separator = ",", string $enclosure = "\"", string $escape = "\\", string $eol = "\n"): int
394+
{
395+
error_clear_last();
396+
if (PHP_VERSION_ID >= 80100) {
397+
/** @phpstan-ignore-next-line */
398+
$result = \fputcsv($stream, $fields, $separator, $enclosure, $escape, $eol);
399+
} else {
400+
$result = \fputcsv($stream, $fields, $separator, $enclosure, $escape);
401+
}
402+
403+
if ($result === false) {
404+
throw FilesystemException::createFromPhpError();
405+
}
406+
return $result;
407+
}

0 commit comments

Comments
 (0)