AbcAeffchen / Sephpa

PHP class to create SEPA xml files for credit transfer and direct debit
GNU Lesser General Public License v3.0
71 stars 31 forks source link

Add Getter getFiles #39

Closed LeisureLarry closed 2 years ago

LeisureLarry commented 2 years ago

For a project I need the possibility to get all files. Would be really great if you could add the getter.

AbcAeffchen commented 2 years ago

When you add a new file to the SephpaMultiFile container using SephpaMultiFile::addFile() you get back a reference to this fie object. In order to make anything with the file you have to store this reference somewhere, e.g. in an array. So this should already do what you need.

LeisureLarry commented 2 years ago

Yes, but it is somewhat annoying to store an extra array which is already present in SephpaMultiFile.

AbcAeffchen commented 2 years ago

Using the references returned by SephpaMultiFile::addFile() ensures that you have the right reference to your file. Using the privately stored array contains the files in some order with only a numeric key by the order the files are added which may or may not change some time. So I don't see much value in this getter function.

$sephpaMultiFile  = new SephpaMultiFile(...);
$files = [];
$files[0] = sephpaMultiFile->addFile(...);
$files[1] = sephpaMultiFile->addFile(...);
$files[2] = sephpaMultiFile->addFile(...);
$files[3] = sephpaMultiFile->addFile(...);

would become

$sephpaMultiFile  = new SephpaMultiFile(...);
$files[0] = sephpaMultiFile->addFile(...);
$files[1] = sephpaMultiFile->addFile(...);
$files[2] = sephpaMultiFile->addFile(...);
$files[3] = sephpaMultiFile->addFile(...);
$files = $sephpaMultFile->getData();

The code does not get shorter or easier, but you lose control over the structure of the array and so the getter function opens potential for bugs and errors.