Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php | ||
| 27 | class CurrencyFactory | ||
| 28 | { | ||
| 29 | |||
| 30 | /** | ||
| 31 | * @var array[] $country_currency_data | ||
| 32 | */ | ||
| 33 | private $country_currency_data; | ||
| 34 | |||
| 35 | /** | ||
| 36 | * @var array[] $country_currencies_by_iso_code | ||
| 37 | */ | ||
| 38 | private $country_currencies_by_iso_code; | ||
| 39 | |||
| 40 | /** | ||
| 41 | * @var array[] $country_currencies_by_currency | ||
| 42 | */ | ||
| 43 | private $country_currencies_by_currency; | ||
| 44 | |||
| 45 | /** | ||
| 46 | * @var string $site_country_iso | ||
| 47 | */ | ||
| 48 | private $site_country_iso; | ||
| 49 | |||
| 50 | |||
| 51 | /** | ||
| 52 | * CurrencyFactory constructor. | ||
| 53 | * | ||
| 54 | * @param EE_Organization_Config $organization_config | ||
| 55 | */ | ||
| 56 |     public function __construct(EE_Organization_Config  $organization_config) { | ||
| 59 | |||
| 60 | |||
| 61 | /** | ||
| 62 | * @return array[] | ||
| 63 | * @throws InvalidArgumentException | ||
| 64 | * @throws EE_Error | ||
| 65 | */ | ||
| 66 | private function getCountryCurrencyData() | ||
| 77 | |||
| 78 | |||
| 79 | /** | ||
| 80 | * @param array[] $country_currency_data | ||
| 81 | * @throws InvalidArgumentException | ||
| 82 | */ | ||
| 83 | private function parseCountryCurrencyData($country_currency_data) | ||
| 91 | |||
| 92 | |||
| 93 | /** | ||
| 94 | * @param array $country_currency | ||
| 95 | * @return Currency | ||
| 96 | */ | ||
| 97 | private function createCurrencyFromCountryCurrency(array $country_currency) | ||
| 113 | |||
| 114 | |||
| 115 | |||
| 116 | /** | ||
| 117 | * returns a Currency object for the supplied country code | ||
| 118 | * | ||
| 119 | * @param string $CNT_ISO | ||
| 120 | * @return Currency | ||
| 121 | * @throws InvalidIdentifierException | ||
| 122 | * @throws InvalidDataTypeException | ||
| 123 | * @throws InvalidInterfaceException | ||
| 124 | * @throws EE_Error | ||
| 125 | * @throws InvalidArgumentException | ||
| 126 | */ | ||
| 127 | public function createFromCountryCode($CNT_ISO = null) | ||
| 146 | |||
| 147 | |||
| 148 | |||
| 149 | /** | ||
| 150 | * returns a Currency object for the supplied currency code | ||
| 151 | * PLZ NOTE: variations may exist between how different countries display the same currency, | ||
| 152 | * so it may be necessary to use CreateCurrency::fromCountryCode() to achieve the desired results | ||
| 153 | * | ||
| 154 | * @param string $code | ||
| 155 | * @return Currency | ||
| 156 | * @throws InvalidIdentifierException | ||
| 157 | * @throws InvalidInterfaceException | ||
| 158 | * @throws InvalidDataTypeException | ||
| 159 | * @throws InvalidArgumentException | ||
| 160 | * @throws EE_Error | ||
| 161 | */ | ||
| 162 | public function createFromCode($code) | ||
| 180 | } | ||
| 181 | // Location: CreateCurrency.php | ||
| 182 |