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 |
||
| 23 | class DomainFactory |
||
| 24 | { |
||
| 25 | /** |
||
| 26 | * @var DomainInterface[] |
||
| 27 | */ |
||
| 28 | protected static $domains = []; |
||
| 29 | |||
| 30 | |||
| 31 | /** |
||
| 32 | * @param FullyQualifiedName $domain_fqcn [required] Fully Qualified Class Name for the Domain class |
||
| 33 | * @param array $arguments [required] array of arguments to be passed to the Domain class |
||
| 34 | * constructor. Must at least include the following two value objects: |
||
| 35 | * array( |
||
| 36 | * EventEspresso\core\domain\values\FilePath $plugin_file |
||
| 37 | * EventEspresso\core\domain\values\Version $version |
||
| 38 | * ) |
||
| 39 | * @return DomainInterface |
||
| 40 | * @throws DomainException |
||
| 41 | * @throws InvalidArgumentException |
||
| 42 | * @throws InvalidDataTypeException |
||
| 43 | * @throws InvalidInterfaceException |
||
| 44 | */ |
||
| 45 | public static function getShared(FullyQualifiedName $domain_fqcn, array $arguments) |
||
| 50 | |||
| 51 | |||
| 52 | /** |
||
| 53 | * @return DomainInterface |
||
| 54 | * @throws DomainException |
||
| 55 | * @throws InvalidArgumentException |
||
| 56 | * @throws InvalidDataTypeException |
||
| 57 | * @throws InvalidFilePathException |
||
| 58 | * @throws InvalidInterfaceException |
||
| 59 | */ |
||
| 60 | public static function getEventEspressoCoreDomain() |
||
| 68 | |||
| 69 | |||
| 70 | /** |
||
| 71 | * @param string $fqcn |
||
| 72 | * @param array $arguments |
||
| 73 | * @return DomainInterface |
||
| 74 | */ |
||
| 75 | private static function getDomain($fqcn, array $arguments) |
||
| 106 | } |
||
| 107 |