Skip to content

Commit

Permalink
Fixed line_number variable, Errors method
Browse files Browse the repository at this point in the history
Variable line_number declaration was missing in method _from_csv. Now
it gets the key number of $row and add 1 to equal the correct line
number. I also created a separate errors() method to get errors from
the object, because getting the static variable couldn’t work for me.
  • Loading branch information
Tamas Erdelyi committed Apr 10, 2014
1 parent f01ec3a commit 2f2a28a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
Binary file removed .DS_Store
Binary file not shown.
15 changes: 12 additions & 3 deletions src/SoapBox/Formatter/Formatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -368,12 +368,12 @@ protected function _from_csv($string, $attributes = array()) {
// Get the headings
$headings = str_replace($escape.$enclosure, $enclosure, str_getcsv(array_shift($rows), $delimiter, $enclosure, $escape));

foreach ($rows as $row) {
foreach ($rows as $line_number => $row) {
$data_fields = str_replace($escape.$enclosure, $enclosure, str_getcsv($row, $delimiter, $enclosure, $escape));
if (count($data_fields) > count($headings)) {
array_push(self::$errors, Lang::get('formatter::formatter.more_data', array('line_number' => $line_number ) ));
array_push(self::$errors, Lang::get('formatter::formatter.more_data', array('line_number' => $line_number + 1) ));
} else if (count($data_fields) < count($headings)) {
array_push(self::$errors, Lang::get('formatter::formatter.less_data', array('line_number' => $line_number ) ));
array_push(self::$errors, Lang::get('formatter::formatter.less_data', array('line_number' => $line_number + 1) ));
} else {
$data[] = array_combine($headings, $data_fields);
}
Expand Down Expand Up @@ -419,4 +419,13 @@ public static function is_assoc($arr) {
}
return false;
}

/**
* Returns with errors
* @return array
*/
public function errors()
{
return self::$errors;
}
}

0 comments on commit 2f2a28a

Please sign in to comment.