Skip to content

Amount for ChargesRecord is not set, if value is "0" #169

@aarongerig

Description

@aarongerig

When parsing an XML-File which contains an amount of a ChargesRecord that has "0" as its value, the amount is not being set on the ChargesRecord object.

Example:

<Chrgs>
    <Rcrd>
        <Amt Ccy="CHF">0</Amt>
        ...
    </Rcd>
</Crgs>

Current behavior

Before setting the amount on the ChargesRecord, the code checks if the amount exists and has a value (here and here). In contrast to other amount values, the "if" statements referenced explicitly expect a "truthy" value. If the value is "0" (string), PHP considers that as "falsy" value and therefore the amount is not set on the ChargesRecord object. For other objects that is not the case (see here).

Expected behavior

If the amount is available, it should also be set on the ChargesRecord object. Otherwise you will get the following error when trying to access the amount via $chargesRecord->getAmount():

Typed property Genkgo\Camt\DTO\ChargesRecord::$amount must not be accessed before initialization

Proposed solution

I suggest to simply remove the && (string) $chargesRecord->Amt part from the "if" statements.

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