Skip to content

Commit 5ed74d5

Browse files
committed
Fixed deprecations.
1 parent 82f5379 commit 5ed74d5

3 files changed

Lines changed: 13 additions & 9 deletions

File tree

composer.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,9 @@
7474
"cs-check": "phpcs",
7575
"cs-fix": "phpcbf",
7676
"test": "phpunit",
77-
"stan": "phpstan analyse && psalm",
77+
"stan": "phpstan analyse",
7878
"phpstan": "phpstan analyse",
79-
"psalm": "psalm --show-info=false",
80-
"stan-setup": "cp composer.json composer.backup && composer require --dev phpstan/phpstan:^1.0.0 vimeo/psalm:^5.0 && mv composer.backup composer.json",
79+
"stan-setup": "cp composer.json composer.backup && composer require --dev phpstan/phpstan:^2.0.0 && mv composer.backup composer.json",
8180
"test-coverage": "phpunit --coverage-clover=clover.xml"
8281
},
8382
"config": {

phpstan.neon

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
parameters:
22
level: 8
3-
checkMissingIterableValueType: false
4-
checkGenericClassInNonGenericObjectType: false
53
paths:
64
- src/
75
bootstrapFiles:
86
- tests/bootstrap.php
7+
ignoreErrors:
8+
- identifier: missingType.generics

src/View/CsvView.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class CsvView extends SerializedView
100100
/**
101101
* List of bom signs for encodings.
102102
*
103-
* @var array
103+
* @var array<string, string>
104104
*/
105105
protected array $bomMap;
106106

@@ -129,6 +129,7 @@ class CsvView extends SerializedView
129129
* - 'delimiter': (default ',') CSV Delimiter, defaults to comma
130130
* - 'enclosure': (default '"') CSV Enclosure for use with fputcsv()
131131
* - 'newline': (default '\n') CSV Newline replacement for use with fputcsv()
132+
* - 'escape': (default '\\') CSV escape character for use with fputcsv()
132133
* - 'eol': (default '\n') End-of-line character the csv
133134
* - 'bom': (default false) Adds BOM (byte order mark) header
134135
* - 'setSeparator': (default false) Adds sep=[_delimiter] in the first line
@@ -146,6 +147,7 @@ class CsvView extends SerializedView
146147
'delimiter' => ',',
147148
'enclosure' => '"',
148149
'newline' => "\n",
150+
'escape' => '\\',
149151
'eol' => PHP_EOL,
150152
'null' => '',
151153
'bom' => false,
@@ -193,7 +195,7 @@ public static function contentType(): string
193195
/**
194196
* Serialize view vars.
195197
*
196-
* @param array|string $serialize The name(s) of the view variable(s) that
198+
* @param array<string>|string $serialize The name(s) of the view variable(s) that
197199
* need(s) to be serialized
198200
* @return string The serialized data or false.
199201
*/
@@ -295,7 +297,7 @@ protected function _renderRow(?array $row = null): string
295297
* data by writing the array to a temporary file and
296298
* returning its contents
297299
*
298-
* @param array|null $row Row data
300+
* @param array<string|null>|null $row Row data
299301
* @return string|false String with the row in csv-syntax, false on fputscv failure
300302
*/
301303
protected function _generateRow(?array $row = null): string|false
@@ -333,20 +335,23 @@ protected function _generateRow(?array $row = null): string|false
333335
$delimiter = $this->getConfig('delimiter');
334336
$enclosure = $this->getConfig('enclosure');
335337
$newline = $this->getConfig('newline');
338+
$escape = $this->getConfig('escape');
336339

340+
/** @phpstan-ignore-next-line */
337341
$row = str_replace(["\r\n", "\n", "\r"], $newline, $row);
338342
if ($enclosure === '') {
339343
// fputcsv does not supports empty enclosure
340344
if (fputs($fp, implode($delimiter, $row) . "\n") === false) {
341345
return false;
342346
}
343347
} else {
344-
if (fputcsv($fp, $row, $delimiter, $enclosure) === false) {
348+
if (fputcsv($fp, $row, $delimiter, $enclosure, $escape) === false) {
345349
return false;
346350
}
347351
}
348352

349353
rewind($fp);
354+
unset($row);
350355

351356
$csv = '';
352357
while (($buffer = fgets($fp, 4096)) !== false) {

0 commit comments

Comments
 (0)