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 |
||
| 21 | View Code Duplication | class ConnectionCollection extends Collection |
|
| 22 | { |
||
| 23 | |||
| 24 | const COLLECTION_NAME = 'espresso_graphql_connections'; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @var CollectionLoader $loader |
||
| 28 | */ |
||
| 29 | protected $loader; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * ConnectionCollection constructor |
||
| 33 | * |
||
| 34 | * @throws InvalidInterfaceException |
||
| 35 | */ |
||
| 36 | public function __construct() |
||
| 43 | |||
| 44 | |||
| 45 | /** |
||
| 46 | * @throws CollectionDetailsException |
||
| 47 | * @throws CollectionLoaderException |
||
| 48 | * @since $VID:$ |
||
| 49 | */ |
||
| 50 | private function loadCollection() |
||
| 76 | |||
| 77 | |||
| 78 | /** |
||
| 79 | * @return CollectionInterface |
||
| 80 | * @throws CollectionDetailsException |
||
| 81 | * @throws CollectionLoaderException |
||
| 82 | * @since $VID:$ |
||
| 83 | */ |
||
| 84 | public function loadConnections() |
||
| 89 | |||
| 90 | |||
| 91 | /** |
||
| 92 | * getIdentifier |
||
| 93 | * Overrides EventEspresso\core\services\collections\Collection::getIdentifier() |
||
| 94 | * If no $identifier is supplied, then the fully qualified class name is used |
||
| 95 | * |
||
| 96 | * @param $object |
||
| 97 | * @param mixed $identifier |
||
| 98 | * @return bool |
||
| 99 | */ |
||
| 100 | public function getIdentifier($object, $identifier = null) |
||
| 106 | } |