Construct array key just once instead for better readability

This commit is contained in:
Christian Bläul
2018-01-21 16:35:29 +01:00
committed by Fonata
parent 63932f67a4
commit 54e846ee30

View File

@@ -609,8 +609,9 @@ class parseCSV {
$this->error = 2; $this->error = 2;
$error_row = count($rows) + 1; $error_row = count($rows) + 1;
$error_col = $col + 1; $error_col = $col + 1;
if (!isset($this->error_info[$error_row . '-' . $error_col])) { $index = $error_row . '-' . $error_col;
$this->error_info[$error_row . '-' . $error_col] = array( if (!isset($this->error_info[$index])) {
$this->error_info[$index] = array(
'type' => 2, 'type' => 2,
'info' => 'Syntax error found on row ' . $error_row . '. Non-enclosed fields can not contain double-quotes.', 'info' => 'Syntax error found on row ' . $error_row . '. Non-enclosed fields can not contain double-quotes.',
'row' => $error_row, 'row' => $error_row,
@@ -636,8 +637,9 @@ class parseCSV {
$error_row = count($rows) + 1; $error_row = count($rows) + 1;
$error_col = $col + 1; $error_col = $col + 1;
if (!isset($this->error_info[$error_row . '-' . $error_col])) { $index = $error_row . '-' . $error_col;
$this->error_info[$error_row . '-' . $error_col] = array( if (!isset($this->error_info[$index])) {
$this->error_info[$index] = array(
'type' => 1, 'type' => 1,
'info' => 'info' =>
'Syntax error found on row ' . (count($rows) + 1) . '. ' . 'Syntax error found on row ' . (count($rows) + 1) . '. ' .
@@ -671,13 +673,17 @@ class parseCSV {
$head = $row; $head = $row;
} elseif (empty($this->fields) || (!empty($this->fields) && (($this->heading && $row_count > 0) || !$this->heading))) { } elseif (empty($this->fields) || (!empty($this->fields) && (($this->heading && $row_count > 0) || !$this->heading))) {
if (!empty($this->sort_by) && !empty($row[$this->sort_by])) { if (!empty($this->sort_by) && !empty($row[$this->sort_by])) {
if (isset($rows[$row[$this->sort_by]])) { $sort_field = $row[$this->sort_by];
$rows[$row[$this->sort_by] . '_0'] = &$rows[$row[$this->sort_by]]; if (isset($rows[$sort_field])) {
unset($rows[$row[$this->sort_by]]); $rows[$sort_field . '_0'] = &$rows[$sort_field];
for ($sn = 1;isset($rows[$row[$this->sort_by] . '_' . $sn]); $sn++) {} unset($rows[$sort_field]);
$rows[$row[$this->sort_by] . '_' . $sn] = $row; $sn = 1;
while (isset($rows[$sort_field . '_' . $sn])) {
$sn++;
}
$rows[$sort_field . '_' . $sn] = $row;
} else { } else {
$rows[$row[$this->sort_by]] = $row; $rows[$sort_field] = $row;
} }
} else { } else {