wimverstuyf / php-coda-parser

PHP parser for Belgian CODA banking files
GNU Lesser General Public License v3.0
41 stars 25 forks source link

Fix error if $transactionCode is null #26

Open woutersamaey opened 2 years ago

wimverstuyf commented 2 years ago

Thanks for the PR! But this doesn't seem to be the correct change:

The TransactionParser allows for the transactioncode to be empty so this would make it a correct change. (Though making this change would mean the getTransactionCode() would also have to be able to return a null value.)

But: The transactioncode can only be empty if no line of type "TransactionPart1" is available. According to the spec this line is mandatory so the transactioncode can only be empty when the CODA-file is malformed. A better solution would be to throw an exception in the TransactionParser when $transactionCode is empty. Agree?

See file https://www.febelfin.be/sites/default/files/2019-04/standard-coda-2.6-nl.pdf Page 6: "2 = beweging. deel 1 is steeds aanwezig, delen 2 en 3 komen voor wanneer nodig."

woutersamaey commented 2 years ago

@wimverstuyf I don't really know. I just noticed that after updating our CODA processor broke on existing files and the code is written in such a way that $transactionCode can be NULL (it is set inside an if), so I assumed it must be nullable. If it is not nullable, an exception is indeed better, but how I'm going to solve my issue is then the bigger question.

One thing I'm also doing is this...

try {
    $statements = $parser->parseFile($file);
} catch (Throwable $t) {
    if($t->getMessage() === 'No data given'){
         // Empty CODA file, we can skip...
         $statements = [];
    }
}

Not the prettiest code, but it seams that empty CODA files throw exceptions instead of returning an empty set. Maybe this is related? I don't know.

PS: I get my CODA files from Codabox using an ING bank account in Belgium.

wimverstuyf commented 2 years ago

Sorry for the late response. Could you provide an example CODA-file which produces this error? Then I'll take a look at it.

woutersamaey commented 2 years ago

@wimverstuyf can I email you the file? I'm not keen on sharing CODA files on Github :)

wimverstuyf commented 2 years ago

sure, you can send it to info [at] eenvoudigfactureren.be