Skip to content

Commit

Permalink
PSR-0
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbonachera committed Jun 6, 2017
1 parent 37678b8 commit 62152cc
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions Parser/PositionalEdiParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,48 +17,48 @@ class PositionalEdiParser implements EdiParserInterface
*/
private $errors = [];

public function parse(array $template = [], array $rows = [], $identifierSize=5)
public function parse(array $template = [], array $rows = [], $identifierSize = 5)
{
if (empty($template)) {
$this->errors["template"] = "No template given";
return false;
}
// Init array
$my_array = [];
$myArray = [];
// SubBody counter
$j = 0;
$my_array["header"] = $this->formatLine($template["header"], $rows[0]);
$myArray["header"] = $this->formatLine($template["header"], $rows[0]);
for ($i = 1; $i < count($rows) - 1; $i++) {
if(is_array($template["body"])) {
foreach ($template["body"] as $index => $templateSubBody) {
if (substr($rows[$i], 0, $identifierSize)==$index) {
$j++;
$my_array["body"][$j][]= $this->formatLine($templateSubBody,$rows[$i]);
continue;
}
if(is_array($templateSubBody)) {
foreach ($templateSubBody as $index2 => $templateSubBody2) {
if(substr($rows[$i], 0, $identifierSize)==$index2) {
$my_array["body"][$j][] = $this->formatLine($templateSubBody2,$rows[$i]);
}
foreach ($template["body"] as $index => $templateSubBody) {
if (substr($rows[$i], 0, $identifierSize) == $index) {
$j++;
$myArray["body"][$j][] = $this->formatLine($templateSubBody, $rows[$i]);
continue;
}
if (is_array($templateSubBody)) {
foreach ($templateSubBody as $index2 => $templateSubBody2) {
if (substr($rows[$i], 0, $identifierSize) == $index2) {
$myArray["body"][$j][] = $this->formatLine($templateSubBody2, $rows[$i]);
}
}
}
continue;
}
continue;
}
$my_array["footer"] = $this->formatLine($template["footer"], $rows[count($rows) - 1]);
return $my_array;
$myArray["footer"] = $this->formatLine($template["footer"], $rows[count($rows) - 1]);
return $myArray;
}
public function formatLine($template, $data, $position=0) {
$my_data=[];
foreach($template as $index => $length) {

public function formatLine($template, $data, $position = 0)
{
$myData = [];
foreach ($template as $index => $length) {
// add current field to array with the named value
$my_data[$index] = substr($data, $position, $length);
$myData[$index] = substr($data, $position, $length);
// move the 'pointer' to the start of the next field
$position += $length;
}
return $my_data;
return $myData;
}

/**
Expand Down

0 comments on commit 62152cc

Please sign in to comment.