vat
                                
                                 vat copied to clipboard
                                
                                    vat copied to clipboard
                            
                            
                            
                        getCountryCodesInEU method
Refactored part of isCountryCodeInEU to a separate method.
Hey, thanks for the PR! Can you elaborate on why you needed the new method, ie what is it used for?
Op 29 dec. 2020 om 22:35 heeft Luca Castellone [email protected] het volgende geschreven:
 Refactored part of isCountryCodeInEU to a separate method.
You can view, comment on, or merge this pull request online at:
https://github.com/ibericode/vat/pull/33
Commit Summary
getCountryCodesInEU method File Changes
M src/Countries.php (17) Patch Links:
https://github.com/ibericode/vat/pull/33.patch https://github.com/ibericode/vat/pull/33.diff — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.
I use the EuCountries array for these data functions:
// [$code => $country_name]
function (){
   $eu = getEuCountryCodes();
   $countries = new Ibericode\Vat\Countries();
   return array_map(function($code)use($countries){
	return $countries[$code];
   },array_combine($eu,$eu));
}
// [$code => $country_rate]
function (){
   $eu = getEuCountryCodes();
   $rates = new Ibericode\Rates\Rates('/path-for-storing-cache-file.txt');
   return array_map(function($code)use($rates){
	return $rates->getRateForCountry($code);
   },array_combine($eu,$eu));
}
Currently to have EuCountries :
function getEuCountryCodes(){
   $ret = [];
   foreach ($countries as $code => $name ) {
	if($countries->isCountryCodeInEU($code)){
		$ret[] = $code;
	}
   }
   return $ret;
}
It will became a simpler $eu = $countries->getCountryCodesInEU()
(The code is an example, real code is wrapped in a class, instances are passed to the constructor and results of loops are memoized)