Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .phive/phars.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<phive xmlns="https://phar.io/phive">
<phar name="phpstan" version="1.10.38" installed="1.10.38" location="./tools/phpstan" copy="false"/>
<phar name="psalm" version="5.15.0" installed="5.15.0" location="./tools/psalm" copy="false"/>
<phar name="phpstan" version="2.1.12" installed="2.1.12" location="./tools/phpstan" copy="false"/>
</phive>
6 changes: 2 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,8 @@
"cs-check": "phpcs",
"cs-fix": "phpcbf",
"test": "phpunit",
"stan": "phpstan analyse && psalm",
"phpstan": "phpstan analyse",
"psalm": "psalm --show-info=false",
"stan-setup": "cp composer.json composer.backup && composer require --dev phpstan/phpstan:^1.0.0 vimeo/psalm:^5.0 && mv composer.backup composer.json",
"stan": "tools/phpstan analyse",
"stan-setup": "phive install",
"test-coverage": "phpunit --coverage-clover=clover.xml"
},
"config": {
Expand Down
4 changes: 2 additions & 2 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
parameters:
level: 8
checkMissingIterableValueType: false
checkGenericClassInNonGenericObjectType: false
paths:
- src/
bootstrapFiles:
- tests/bootstrap.php
ignoreErrors:
- identifier: missingType.generics
24 changes: 0 additions & 24 deletions psalm.xml

This file was deleted.

2 changes: 1 addition & 1 deletion src/CsvViewPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function bootstrap(PluginApplicationInterface $app): void
'accept' => ['text/csv'],
'param' => '_ext',
'value' => 'csv',
]
],
);
}
}
13 changes: 9 additions & 4 deletions src/View/CsvView.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class CsvView extends SerializedView
/**
* List of bom signs for encodings.
*
* @var array
* @var array<string, string>
*/
protected array $bomMap;

Expand Down Expand Up @@ -129,6 +129,7 @@ class CsvView extends SerializedView
* - 'delimiter': (default ',') CSV Delimiter, defaults to comma
* - 'enclosure': (default '"') CSV Enclosure for use with fputcsv()
* - 'newline': (default '\n') CSV Newline replacement for use with fputcsv()
* - 'escape': (default '\\') CSV escape character for use with fputcsv()
* - 'eol': (default '\n') End-of-line character the csv
* - 'bom': (default false) Adds BOM (byte order mark) header
* - 'setSeparator': (default false) Adds sep=[_delimiter] in the first line
Expand All @@ -146,6 +147,7 @@ class CsvView extends SerializedView
'delimiter' => ',',
'enclosure' => '"',
'newline' => "\n",
'escape' => '\\',
'eol' => PHP_EOL,
'null' => '',
'bom' => false,
Expand Down Expand Up @@ -193,7 +195,7 @@ public static function contentType(): string
/**
* Serialize view vars.
*
* @param array|string $serialize The name(s) of the view variable(s) that
* @param array<string>|string $serialize The name(s) of the view variable(s) that
* need(s) to be serialized
* @return string The serialized data or false.
*/
Expand Down Expand Up @@ -295,7 +297,7 @@ protected function _renderRow(?array $row = null): string
* data by writing the array to a temporary file and
* returning its contents
*
* @param array|null $row Row data
* @param array<string|null>|null $row Row data
* @return string|false String with the row in csv-syntax, false on fputscv failure
*/
protected function _generateRow(?array $row = null): string|false
Expand Down Expand Up @@ -333,20 +335,23 @@ protected function _generateRow(?array $row = null): string|false
$delimiter = $this->getConfig('delimiter');
$enclosure = $this->getConfig('enclosure');
$newline = $this->getConfig('newline');
$escape = $this->getConfig('escape');

/** @phpstan-ignore-next-line */
$row = str_replace(["\r\n", "\n", "\r"], $newline, $row);
if ($enclosure === '') {
// fputcsv does not supports empty enclosure
if (fputs($fp, implode($delimiter, $row) . "\n") === false) {
return false;
}
} else {
if (fputcsv($fp, $row, $delimiter, $enclosure) === false) {
if (fputcsv($fp, $row, $delimiter, $enclosure, $escape) === false) {
return false;
}
}

rewind($fp);
unset($row);

$csv = '';
while (($buffer = fgets($fp, 4096)) !== false) {
Expand Down
8 changes: 4 additions & 4 deletions tests/TestCase/View/CsvViewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function testBom()
{
if (!extension_loaded('mbstring')) {
$this->markTestSkipped(
'The mbstring extension is not available.'
'The mbstring extension is not available.',
);
}

Expand All @@ -91,7 +91,7 @@ public function testBomMultipleContentRows()
{
if (!extension_loaded('mbstring')) {
$this->markTestSkipped(
'The mbstring extension is not available.'
'The mbstring extension is not available.',
);
}

Expand All @@ -118,7 +118,7 @@ public function testBomMultipleContentRowsWithHeader()
{
if (!extension_loaded('mbstring')) {
$this->markTestSkipped(
'The mbstring extension is not available.'
'The mbstring extension is not available.',
);
}

Expand Down Expand Up @@ -215,7 +215,7 @@ public function testRenderWithMbstring()
{
if (!extension_loaded('mbstring')) {
$this->markTestSkipped(
'The mbstring extension is not available.'
'The mbstring extension is not available.',
);
}
$data = [
Expand Down