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 |
||
| 28 | class CreateCurrency |
||
| 29 | { |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @var EE_Country[] $countries |
||
| 33 | */ |
||
| 34 | protected static $countries_by_iso_code; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @var EE_Country[] $countries |
||
| 38 | */ |
||
| 39 | protected static $countries_by_currency; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @var string $site_country_iso |
||
| 43 | */ |
||
| 44 | protected static $site_country_iso; |
||
| 45 | |||
| 46 | |||
| 47 | /** |
||
| 48 | * @return EEM_Country |
||
| 49 | * @throws InvalidArgumentException |
||
| 50 | * @throws InvalidDataTypeException |
||
| 51 | * @throws InvalidInterfaceException |
||
| 52 | */ |
||
| 53 | private static function countryModel() |
||
| 57 | |||
| 58 | |||
| 59 | /** |
||
| 60 | * returns a Currency object for the supplied country code |
||
| 61 | * |
||
| 62 | * @param string $CNT_ISO |
||
| 63 | * @return Currency |
||
| 64 | * @throws InvalidDataTypeException |
||
| 65 | * @throws InvalidInterfaceException |
||
| 66 | * @throws EE_Error |
||
| 67 | * @throws InvalidArgumentException |
||
| 68 | */ |
||
| 69 | public static function fromCountryCode($CNT_ISO = null) |
||
| 104 | |||
| 105 | |||
| 106 | |||
| 107 | /** |
||
| 108 | * returns a Currency object for the supplied currency code |
||
| 109 | * PLZ NOTE: variations may exist between how different countries display the same currency, |
||
| 110 | * so it may be necessary to use CreateCurrency::fromCountryCode() to achieve the desired results |
||
| 111 | * |
||
| 112 | * @param string $code |
||
| 113 | * @return Currency |
||
| 114 | * @throws InvalidInterfaceException |
||
| 115 | * @throws InvalidDataTypeException |
||
| 116 | * @throws InvalidArgumentException |
||
| 117 | * @throws EE_Error |
||
| 118 | */ |
||
| 119 | public static function fromCode($code) |
||
| 153 | |||
| 154 | |||
| 155 | |||
| 156 | /** |
||
| 157 | * @return string |
||
| 158 | * @throws InvalidArgumentException |
||
| 159 | * @throws InvalidDataTypeException |
||
| 160 | * @throws InvalidInterfaceException |
||
| 161 | */ |
||
| 162 | public static function getSiteCountryIso() |
||
| 173 | |||
| 174 | |||
| 175 | |||
| 176 | } |
||
| 177 | // Location: CreateCurrency.php |
||
| 178 |