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 |
||
| 24 | class CurrencyFactory |
||
| 25 | { |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @var array[] $country_currency_data |
||
| 29 | */ |
||
| 30 | private $country_currency_data; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @var array[] $country_currencies_by_iso_code |
||
| 34 | */ |
||
| 35 | private $country_currencies_by_iso_code; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @var array[] $country_currencies_by_currency |
||
| 39 | */ |
||
| 40 | private $country_currencies_by_currency; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @var string $site_country_iso |
||
| 44 | */ |
||
| 45 | private $site_country_iso; |
||
| 46 | |||
| 47 | |||
| 48 | /** |
||
| 49 | * CurrencyFactory constructor. |
||
| 50 | * |
||
| 51 | * @param EE_Organization_Config $organization_config |
||
| 52 | */ |
||
| 53 | public function __construct(EE_Organization_Config $organization_config) { |
||
| 56 | |||
| 57 | |||
| 58 | /** |
||
| 59 | * @return array[] |
||
| 60 | * @throws EE_Error |
||
| 61 | */ |
||
| 62 | private function getCountryCurrencyData() |
||
| 73 | |||
| 74 | |||
| 75 | /** |
||
| 76 | * @param array[] $country_currency_data |
||
| 77 | */ |
||
| 78 | private function parseCountryCurrencyData($country_currency_data) |
||
| 86 | |||
| 87 | |||
| 88 | /** |
||
| 89 | * @param array $country_currency |
||
| 90 | * @return Currency |
||
| 91 | */ |
||
| 92 | private function createCurrencyFromCountryCurrency(array $country_currency) |
||
| 108 | |||
| 109 | |||
| 110 | |||
| 111 | /** |
||
| 112 | * returns a Currency object for the supplied country code |
||
| 113 | * |
||
| 114 | * @param string $CNT_ISO |
||
| 115 | * @return Currency |
||
| 116 | * @throws EE_Error |
||
| 117 | * @throws InvalidArgumentException |
||
| 118 | */ |
||
| 119 | public function createFromCountryCode($CNT_ISO = null) |
||
| 138 | |||
| 139 | |||
| 140 | |||
| 141 | /** |
||
| 142 | * returns a Currency object for the supplied currency code |
||
| 143 | * PLZ NOTE: variations may exist between how different countries display the same currency, |
||
| 144 | * so it may be necessary to use CreateCurrency::fromCountryCode() to achieve the desired results |
||
| 145 | * |
||
| 146 | * @param string $code |
||
| 147 | * @return Currency |
||
| 148 | * @throws InvalidArgumentException |
||
| 149 | * @throws EE_Error |
||
| 150 | */ |
||
| 151 | public function createFromCode($code) |
||
| 169 | } |
||
| 170 | // Location: CreateCurrency.php |
||
| 171 |