Skip to content

Commit

Permalink
Merge pull request #7 from terdelyi/master
Browse files Browse the repository at this point in the history
Fixed line_number variable, Errors method
  • Loading branch information
grahammccarthy committed Apr 15, 2014
2 parents f01ec3a + 2f2a28a commit 4a7b9df
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 4a7b9df

Please sign in to comment.