Skip to content

Commit

Permalink
Don't warn when segment ID is same as first segment in the group
Browse files Browse the repository at this point in the history
  • Loading branch information
sabas committed Mar 6, 2024
1 parent e4903a8 commit dffa093
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/EDI/Interpreter.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ class Interpreter
*/
private $currentGroup = '';

/**
* @var string
*/
private $currentGroupHeader = '';

/**
* Split multiple messages and process
*
Expand Down Expand Up @@ -502,6 +507,9 @@ private function processXmlGroup(\SimpleXMLElement $elm, array &$message, int &$
$groupVisited = false;
$newGroup = [];

$this->currentGroupHeader = $message[$segmentIdx][0];
$this->currentGroup = $elm['id']->__toString();

for ($g = 0; $g < $elm['maxrepeat']; $g++) {
$grouptemp = [];
if ($message[$segmentIdx][0] != $elm->children()[0]['id']) {
Expand All @@ -527,8 +535,6 @@ private function processXmlGroup(\SimpleXMLElement $elm, array &$message, int &$
}
}

$this->currentGroup = $elm['id']->__toString();

foreach ($elm->children() as $elm2) {
if ($elm2->getName() == 'group') {
$this->processXmlGroup($elm2, $message, $segmentIdx, $grouptemp, $errors);
Expand Down Expand Up @@ -562,6 +568,9 @@ private function processXmlGroup(\SimpleXMLElement $elm, array &$message, int &$
$newGroup[] = $grouptemp;
}

$this->currentGroupHeader = '';
$this->currentGroup = '';

if (\count($newGroup) === 0) {
return;
}
Expand Down Expand Up @@ -657,7 +666,11 @@ private function processXmlSegment(\SimpleXMLElement $elm, array &$message, int

// if additional segments are detected we are violating the maxrepeat attribute
$loopMove = 0;
while (isset($message[$segmentIdx]) && \call_user_func($this->comparisonFunction, $message[$segmentIdx+$loopMove], $elm)) {
while (
isset($message[$segmentIdx]) &&
\call_user_func($this->comparisonFunction, $message[$segmentIdx+$loopMove], $elm) &&
(string)$elm['id'] !== $this->currentGroupHeader
) {
$errors[] = [
'text' => $this->messageTextConf['TOOMANYSEGMENTS'].($this->patchFiles ? ' (skipped)' : ''),
'position' => $segmentIdx,
Expand Down

0 comments on commit dffa093

Please sign in to comment.