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 EEM_Country $country_model |
||
| 32 | */ |
||
| 33 | protected $country_model; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @var EE_Country[] $countries |
||
| 37 | */ |
||
| 38 | protected $countries_by_iso_code; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @var EE_Country[] $countries |
||
| 42 | */ |
||
| 43 | protected $countries_by_currency; |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @var EE_Organization_Config $organization_config |
||
| 47 | */ |
||
| 48 | protected $organization_config; |
||
| 49 | |||
| 50 | /** |
||
| 51 | * @var string $site_country_iso |
||
| 52 | */ |
||
| 53 | protected $site_country_iso; |
||
| 54 | |||
| 55 | |||
| 56 | /** |
||
| 57 | * CurrencyFactory constructor. |
||
| 58 | * |
||
| 59 | * @param EEM_Country $country_model |
||
| 60 | * @param EE_Organization_Config $organization_config |
||
| 61 | */ |
||
| 62 | public function __construct(EEM_Country $country_model, EE_Organization_Config $organization_config) |
||
| 67 | |||
| 68 | |||
| 69 | /** |
||
| 70 | * returns a Currency object for the supplied country code |
||
| 71 | * |
||
| 72 | * @param string $CNT_ISO |
||
| 73 | * @return Currency |
||
| 74 | * @throws InvalidDataTypeException |
||
| 75 | * @throws InvalidInterfaceException |
||
| 76 | * @throws EE_Error |
||
| 77 | * @throws InvalidArgumentException |
||
| 78 | */ |
||
| 79 | public function createFromCountryCode($CNT_ISO = null) |
||
| 114 | |||
| 115 | |||
| 116 | |||
| 117 | /** |
||
| 118 | * returns a Currency object for the supplied currency code |
||
| 119 | * PLZ NOTE: variations may exist between how different countries display the same currency, |
||
| 120 | * so it may be necessary to use CreateCurrency::fromCountryCode() to achieve the desired results |
||
| 121 | * |
||
| 122 | * @param string $code |
||
| 123 | * @return Currency |
||
| 124 | * @throws InvalidInterfaceException |
||
| 125 | * @throws InvalidDataTypeException |
||
| 126 | * @throws InvalidArgumentException |
||
| 127 | * @throws EE_Error |
||
| 128 | */ |
||
| 129 | public function createFromCode($code) |
||
| 163 | |||
| 164 | |||
| 165 | |||
| 166 | |||
| 167 | } |
||
| 168 | // Location: CreateCurrency.php |
||
| 169 |