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 |
||
| 12 | class XrefResolverFactory |
||
| 13 | { |
||
| 14 | /** @var XrefResolverInterface[] */ |
||
| 15 | protected static $registeredByType = array(); |
||
| 16 | |||
| 17 | /** |
||
| 18 | * Register all known resolvers. |
||
| 19 | */ |
||
| 20 | 7 | protected static function registerKnownTypes() |
|
| 29 | |||
| 30 | /** |
||
| 31 | * Get a registered resolver for the given type. |
||
| 32 | * |
||
| 33 | * @param string $xrefType |
||
| 34 | * @return XrefResolverInterface |
||
| 35 | * |
||
| 36 | * @throws UnknownXrefTypeException |
||
| 37 | */ |
||
| 38 | 7 | View Code Duplication | public static function getByType($xrefType) |
| 46 | |||
| 47 | /** |
||
| 48 | * Check if the given resolver is registerd. |
||
| 49 | * |
||
| 50 | * @param XrefResolverInterface $xrefResolver |
||
| 51 | * @return boolean |
||
| 52 | */ |
||
| 53 | public static function isRegistered(XrefResolverInterface $xrefResolver) |
||
| 57 | |||
| 58 | /** |
||
| 59 | * Used internally to register a new resolver. |
||
| 60 | * |
||
| 61 | * @param XrefResolverInterface $xrefResolver |
||
| 62 | */ |
||
| 63 | 1 | protected static function internalRegister(XrefResolverInterface $xrefResolver) |
|
| 67 | |||
| 68 | /** |
||
| 69 | * Register a new resolver. |
||
| 70 | * |
||
| 71 | * @param XrefResolverInterface $xrefResolver |
||
| 72 | * @throws AlreadyRegisteredException |
||
| 73 | */ |
||
| 74 | View Code Duplication | public static function register(XrefResolverInterface $xrefResolver) |
|
| 86 | } |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.