Made PhpStorm inspections happy:

- avoid empty for-loop bodies as they are unusual and look a bit like
  forgotten implementations
- removed 'i' modifier from regular expressions that contain no letters
- replaced consecutive 'str_replace' calls by single 'strtr' call
- introduced new variable $is_newline to make the intend of a complex
  'if' more obvious and get rid of the operator precedence inspection
This commit is contained in:
Christian Bläul
2018-01-21 16:45:43 +01:00
committed by Fonata
parent a92506d078
commit d8aefa792e

View File

@@ -626,7 +626,10 @@ class parseCSV {
$current .= $ch; $current .= $ch;
$i++; $i++;
} elseif ($nch != $this->delimiter && $nch != "\r" && $nch != "\n") { } elseif ($nch != $this->delimiter && $nch != "\r" && $nch != "\n") {
for ($x = ($i + 1);isset($data{$x}) && ltrim($data{$x}, $white_spaces) == ''; $x++) {} $x = $i + 1;
while (isset($data{$x}) && ltrim($data{$x}, $white_spaces) == '') {
$x++;
}
if ($data{$x} == $this->delimiter) { if ($data{$x} == $this->delimiter) {
$enclosed = false; $enclosed = false;
$i = $x; $i = $x;
@@ -814,7 +817,7 @@ class parseCSV {
$this->file = $file; $this->file = $file;
} }
if (preg_match('/\.php$/i', $file) && preg_match('/<\?.*?\?>(.*)/ims', $data, $strip)) { if (preg_match('/\.php$/', $file) && preg_match('/<\?.*?\?>(.*)/ms', $data, $strip)) {
$data = ltrim($strip[1]); $data = ltrim($strip[1]);
} }
@@ -925,12 +928,14 @@ class parseCSV {
$op = $capture[2]; $op = $capture[2];
$value = $capture[3]; $value = $capture[3];
if (preg_match('/^([\'\"]{1})(.*)([\'\"]{1})$/i', $value, $capture)) { if (preg_match('/^([\'\"]{1})(.*)([\'\"]{1})$/', $value, $capture)) {
if ($capture[1] == $capture[3]) { if ($capture[1] == $capture[3]) {
$value = $capture[2]; $value = strtr($capture[2], array(
$value = str_replace("\\n", "\n", $value); "\\n" => "\n",
$value = str_replace("\\r", "\r", $value); "\\r" => "\r",
$value = str_replace("\\t", "\t", $value); "\\t" => "\t",
));
$value = stripslashes($value); $value = stripslashes($value);
} }
} }
@@ -969,11 +974,10 @@ class parseCSV {
* @return true of false * @return true of false
*/ */
protected function _validate_offset($current_row) { protected function _validate_offset($current_row) {
if ($this->sort_by === null && $this->offset !== null && $current_row < $this->offset) { return
return false; $this->sort_by !== null ||
} $this->offset === null ||
$current_row >= $this->offset;
return true;
} }
/** /**
@@ -1153,6 +1157,7 @@ class parseCSV {
} }
// remove delimiter and its line-end (the data param is by-ref!) // remove delimiter and its line-end (the data param is by-ref!)
/** @noinspection CallableParameterUseCaseInTypeContextInspection */
$data_string = substr($data_string, $pos); $data_string = substr($data_string, $pos);
return true; return true;
} }
@@ -1178,6 +1183,7 @@ class parseCSV {
$pch = isset($data{$i - 1}) ? $data{$i - 1} : false; $pch = isset($data{$i - 1}) ? $data{$i - 1} : false;
// open and closing quotes // open and closing quotes
$is_newline = ($ch == "\n" && $pch != "\r") || $ch == "\r";
if ($ch == $enclosure) { if ($ch == $enclosure) {
if (!$enclosed || $nch != $enclosure) { if (!$enclosed || $nch != $enclosure) {
$enclosed = $enclosed ? false : true; $enclosed = $enclosed ? false : true;
@@ -1186,7 +1192,7 @@ class parseCSV {
} }
// end of row // end of row
} elseif (($ch == "\n" && $pch != "\r" || $ch == "\r") && !$enclosed) { } elseif ($is_newline && !$enclosed) {
if ($current_row >= $search_depth) { if ($current_row >= $search_depth) {
$strlen = 0; $strlen = 0;
$to_end = false; $to_end = false;