Closed nyamsprod closed 8 years ago
This changes far more than necessary in my humble opinion. Those who want to provide an alternate data set, probably know what they are doing, and thus validation is really not required.
Since you don't want a simple country value object at least you should validate the input data.
Adding the validation/normalization steps enables:
I've move the validation out in another class. So If the developer wants to validate his data prior to instantiation he can do it with the new class. Then he simply injects the new list into ISO3166 constructor
<?php
use League\ISO3166\ISO3166;
use League\ISO3166\CountryValidator;
$input_data; //some country data in an array
$validator = new CountryValidator();
$collection = new ISO3166($validator->validateMany($input_data));
The use of the CountryValidator is not required but highly recommended if you are not sure about your input data.
I can see the use-case for a validator, though I would rather call it DataValidator, not specifically CountryValidator. Let me tinker around a bit and come up with a counter proposal.
The names can be changed this is only a proposal 👍
Can you give me your thoughts on #18?