From df27aff53473443f75edffa88f44ca363abb1a61 Mon Sep 17 00:00:00 2001 From: Benjamin Perche Date: Fri, 1 Aug 2014 16:30:06 +0200 Subject: [PATCH] =?UTF-8?q?Fix=20usage=20=09modifi=C3=A9:=20=20=20=20=20?= =?UTF-8?q?=20=20=20=20core/lib/Thelia/Core/FileFormat/Formatting/Formatte?= =?UTF-8?q?r/CSVFormatter.php?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Formatting/Formatter/CSVFormatter.php | 57 +++++++++---------- 1 file changed, 26 insertions(+), 31 deletions(-) diff --git a/core/lib/Thelia/Core/FileFormat/Formatting/Formatter/CSVFormatter.php b/core/lib/Thelia/Core/FileFormat/Formatting/Formatter/CSVFormatter.php index 4a42db3b0..4b6069bdc 100644 --- a/core/lib/Thelia/Core/FileFormat/Formatting/Formatter/CSVFormatter.php +++ b/core/lib/Thelia/Core/FileFormat/Formatting/Formatter/CSVFormatter.php @@ -84,7 +84,7 @@ class CSVFormatter extends AbstractFormatter $delimiterLength = strlen($this->delimiter); $lineReturnLength = strlen($this->lineReturn); - if ($firstRow === null) { + if ($firstRow === false) { return ""; } @@ -93,43 +93,38 @@ class CSVFormatter extends AbstractFormatter */ $this->checkOrders($firstRow); - if (false !== $firstRow) { - $rawKeys = array_keys($firstRow); - $keys = []; + $rawKeys = array_keys($firstRow); + $keys = []; - foreach ($rawKeys as $key) { - $keys[$key] = $key; + foreach ($rawKeys as $key) { + $keys[$key] = $key; + } + + $values = $data->getData(); + array_unshift($values, $keys); + + while (null !== $row = array_shift($values)) { + /** + * First put the sorted ones + */ + foreach ($this->order as $order) { + $string .= $this->formatField($row[$order]); + unset($row[$order]); } - $values = $data->getData(); - array_unshift($values, $keys); + /** + * Then place the fields, + * order by name + */ + ksort($row); - while (null !== $row = array_shift($values)) { - /** - * First put the sorted ones - */ - foreach ($this->order as $order) { - $string .= $this->formatField($row[$order]); - unset($row[$order]); + foreach ($keys as $key) { + if (array_key_exists($key, $row)) { + $string .= $this->formatField($row[$key]); } - - /** - * Then place the fields, - * order by name - */ - ksort($row); - - foreach ($keys as $key) { - if (array_key_exists($key, $row)) { - $string .= $this->formatField($row[$key]); - } - } - - $string = substr($string,0, -$delimiterLength) . $this->lineReturn; } - } else { - $lineReturnLength = 0; + $string = substr($string,0, -$delimiterLength) . $this->lineReturn; } return substr($string, 0, -$lineReturnLength);