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 string $domain_fqcn [required] Fully Qualified Class Name for the Domain class |
||
| 33 | * @param string $main_file [required] path to the main plugin file |
||
| 34 | * @param string $version [required] version string for the plugin |
||
| 35 | * @return DomainInterface |
||
| 36 | * @throws DomainException |
||
| 37 | * @throws InvalidArgumentException |
||
| 38 | * @throws InvalidDataTypeException |
||
| 39 | * @throws InvalidInterfaceException |
||
| 40 | */ |
||
| 41 | public static function create(string $domain_fqcn, string $main_file, string $version): DomainInterface |
||
| 46 | |||
| 47 | |||
| 48 | /** |
||
| 49 | * @param FullyQualifiedName $domain_fqcn [required] Fully Qualified Class Name for the Domain class |
||
| 50 | * @param array $arguments [required] array of arguments to be passed to the Domain class |
||
| 51 | * constructor. Must at least include the following two value objects: |
||
| 52 | * [ |
||
| 53 | * EventEspresso\core\domain\values\FilePath $plugin_file |
||
| 54 | * EventEspresso\core\domain\values\Version $version |
||
| 55 | * ] |
||
| 56 | * @return DomainInterface |
||
| 57 | * @throws DomainException |
||
| 58 | * @throws InvalidArgumentException |
||
| 59 | * @throws InvalidDataTypeException |
||
| 60 | * @throws InvalidInterfaceException |
||
| 61 | */ |
||
| 62 | public static function getShared(FullyQualifiedName $domain_fqcn, array $arguments): DomainInterface |
||
| 66 | |||
| 67 | |||
| 68 | /** |
||
| 69 | * @return DomainInterface |
||
| 70 | * @throws DomainException |
||
| 71 | * @throws InvalidArgumentException |
||
| 72 | * @throws InvalidDataTypeException |
||
| 73 | * @throws InvalidFilePathException |
||
| 74 | * @throws InvalidInterfaceException |
||
| 75 | */ |
||
| 76 | public static function getEventEspressoCoreDomain(): DomainInterface |
||
| 84 | |||
| 85 | |||
| 86 | /** |
||
| 87 | * @param string $fqcn |
||
| 88 | * @param array $arguments |
||
| 89 | * @return DomainInterface |
||
| 90 | */ |
||
| 91 | private static function getDomain(string $fqcn, array $arguments): DomainInterface |
||
| 122 | } |
||
| 123 |