Skip to content

Elements with maxrepeat > 1 should be considered arrays when parsed as json #124

Closed
@proggeler

Description

@proggeler

When using EDI\Interpreter::getJson(); it would be very helpful if the parts within the json would have a consistent type.

For example: According to the INVOIC (D96A) message the message can contain up to 35 DTM entries.
This causes for a lot of if statements within code that processes these date entries:

$invoices = json_decode($interpreter->getJson());
$invoice = $invoices[0];

if (!is_array($invoice->datetimeperiod)) {
    // ensure it is an array before processing it (maxrepeat = 35)
    $invoice->datetimeperiod = [$invoice->datetimeperiod->datetimeperiod];
}
$dates = [];
foreach ($invoice->datetimeperiod as $datetimeperiod) {
    if ($datetimeperiod->datetimeperiodFormatQualifier == 102) {
        $dates[] = DateTimeImmutable::createFromFormat('Ymd', $datetimeperiod->datetimeperiod); 
    }
}

This check for the array needs to be done for all the elements that have a maxrepeat > 1.

If the maxrepeat > 1 is used by the interpreter to force an array, implementation would be more predictable and the code would be more clean.

This also counts for EDI\Interpreter::getArrayy()->getArray(true)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions