Skip to content

Commit 0c4d733

Browse files
authored
Merge pull request #145 from FriendsOfCake/fix-depr
Fixed deprecations.
2 parents 82f5379 + d534c4b commit 0c4d733

File tree

7 files changed

+19
-41
lines changed

7 files changed

+19
-41
lines changed

.phive/phars.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<phive xmlns="https://phar.io/phive">
3-
<phar name="phpstan" version="1.10.38" installed="1.10.38" location="./tools/phpstan" copy="false"/>
4-
<phar name="psalm" version="5.15.0" installed="5.15.0" location="./tools/psalm" copy="false"/>
3+
<phar name="phpstan" version="2.1.12" installed="2.1.12" location="./tools/phpstan" copy="false"/>
54
</phive>

composer.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,8 @@
7474
"cs-check": "phpcs",
7575
"cs-fix": "phpcbf",
7676
"test": "phpunit",
77-
"stan": "phpstan analyse && psalm",
78-
"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",
77+
"stan": "tools/phpstan analyse",
78+
"stan-setup": "phive install",
8179
"test-coverage": "phpunit --coverage-clover=clover.xml"
8280
},
8381
"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

psalm.xml

Lines changed: 0 additions & 24 deletions
This file was deleted.

src/CsvViewPlugin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function bootstrap(PluginApplicationInterface $app): void
4747
'accept' => ['text/csv'],
4848
'param' => '_ext',
4949
'value' => 'csv',
50-
]
50+
],
5151
);
5252
}
5353
}

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) {

tests/TestCase/View/CsvViewTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function testBom()
6969
{
7070
if (!extension_loaded('mbstring')) {
7171
$this->markTestSkipped(
72-
'The mbstring extension is not available.'
72+
'The mbstring extension is not available.',
7373
);
7474
}
7575

@@ -91,7 +91,7 @@ public function testBomMultipleContentRows()
9191
{
9292
if (!extension_loaded('mbstring')) {
9393
$this->markTestSkipped(
94-
'The mbstring extension is not available.'
94+
'The mbstring extension is not available.',
9595
);
9696
}
9797

@@ -118,7 +118,7 @@ public function testBomMultipleContentRowsWithHeader()
118118
{
119119
if (!extension_loaded('mbstring')) {
120120
$this->markTestSkipped(
121-
'The mbstring extension is not available.'
121+
'The mbstring extension is not available.',
122122
);
123123
}
124124

@@ -215,7 +215,7 @@ public function testRenderWithMbstring()
215215
{
216216
if (!extension_loaded('mbstring')) {
217217
$this->markTestSkipped(
218-
'The mbstring extension is not available.'
218+
'The mbstring extension is not available.',
219219
);
220220
}
221221
$data = [

0 commit comments

Comments
 (0)