diff --git a/.phive/phars.xml b/.phive/phars.xml index d2fe06f..e88c784 100644 --- a/.phive/phars.xml +++ b/.phive/phars.xml @@ -1,5 +1,4 @@ - - + diff --git a/composer.json b/composer.json index c0bbb6a..00f0aef 100644 --- a/composer.json +++ b/composer.json @@ -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": { diff --git a/phpstan.neon b/phpstan.neon index 89d9c92..c1a0f31 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,8 +1,8 @@ parameters: level: 8 - checkMissingIterableValueType: false - checkGenericClassInNonGenericObjectType: false paths: - src/ bootstrapFiles: - tests/bootstrap.php + ignoreErrors: + - identifier: missingType.generics diff --git a/psalm.xml b/psalm.xml deleted file mode 100644 index 8dedfd9..0000000 --- a/psalm.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - - - - - - - - - - - diff --git a/src/CsvViewPlugin.php b/src/CsvViewPlugin.php index e3755c3..19d00a4 100644 --- a/src/CsvViewPlugin.php +++ b/src/CsvViewPlugin.php @@ -47,7 +47,7 @@ public function bootstrap(PluginApplicationInterface $app): void 'accept' => ['text/csv'], 'param' => '_ext', 'value' => 'csv', - ] + ], ); } } diff --git a/src/View/CsvView.php b/src/View/CsvView.php index 571dc0b..679587c 100644 --- a/src/View/CsvView.php +++ b/src/View/CsvView.php @@ -100,7 +100,7 @@ class CsvView extends SerializedView /** * List of bom signs for encodings. * - * @var array + * @var array */ protected array $bomMap; @@ -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 @@ -146,6 +147,7 @@ class CsvView extends SerializedView 'delimiter' => ',', 'enclosure' => '"', 'newline' => "\n", + 'escape' => '\\', 'eol' => PHP_EOL, 'null' => '', 'bom' => false, @@ -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 $serialize The name(s) of the view variable(s) that * need(s) to be serialized * @return string The serialized data or false. */ @@ -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|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 @@ -333,7 +335,9 @@ 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 @@ -341,12 +345,13 @@ protected function _generateRow(?array $row = null): string|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) { diff --git a/tests/TestCase/View/CsvViewTest.php b/tests/TestCase/View/CsvViewTest.php index 4dad49b..2c2b11c 100644 --- a/tests/TestCase/View/CsvViewTest.php +++ b/tests/TestCase/View/CsvViewTest.php @@ -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.', ); } @@ -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.', ); } @@ -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.', ); } @@ -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 = [