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 |
||
| 26 | class ObjectPersister implements ObjectPersisterInterface |
||
| 27 | { |
||
| 28 | protected $type; |
||
| 29 | protected $transformer; |
||
| 30 | protected $objectClass; |
||
| 31 | protected $fields; |
||
| 32 | protected $logger; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @param Type $type |
||
| 36 | * @param ModelToElasticaTransformerInterface $transformer |
||
| 37 | * @param string $objectClass |
||
| 38 | * @param array $fields |
||
| 39 | */ |
||
| 40 | 17 | public function __construct(Type $type, ModelToElasticaTransformerInterface $transformer, $objectClass, array $fields) |
|
| 47 | |||
| 48 | /** |
||
| 49 | * {@inheritdoc} |
||
| 50 | */ |
||
| 51 | public function handlesObject($object) |
||
| 55 | |||
| 56 | /** |
||
| 57 | * @param LoggerInterface $logger |
||
| 58 | */ |
||
| 59 | public function setLogger(LoggerInterface $logger) |
||
| 63 | |||
| 64 | /** |
||
| 65 | * {@inheritdoc} |
||
| 66 | */ |
||
| 67 | 7 | public function insertOne($object) |
|
| 71 | |||
| 72 | /** |
||
| 73 | * {@inheritdoc} |
||
| 74 | */ |
||
| 75 | 5 | public function replaceOne($object) |
|
| 79 | |||
| 80 | /** |
||
| 81 | * {@inheritdoc} |
||
| 82 | */ |
||
| 83 | 3 | public function deleteOne($object) |
|
| 87 | |||
| 88 | /** |
||
| 89 | * {@inheritdoc} |
||
| 90 | */ |
||
| 91 | public function deleteById($id) |
||
| 95 | |||
| 96 | /** |
||
| 97 | * {@inheritdoc} |
||
| 98 | */ |
||
| 99 | 10 | View Code Duplication | public function insertMany(array $objects) |
| 111 | |||
| 112 | /** |
||
| 113 | * {@inheritdoc} |
||
| 114 | */ |
||
| 115 | 5 | public function replaceMany(array $objects) |
|
| 130 | |||
| 131 | /** |
||
| 132 | * {@inheritdoc} |
||
| 133 | */ |
||
| 134 | 3 | View Code Duplication | public function deleteMany(array $objects) |
| 146 | |||
| 147 | /** |
||
| 148 | * {@inheritdoc} |
||
| 149 | */ |
||
| 150 | public function deleteManyByIdentifiers(array $identifiers) |
||
| 158 | |||
| 159 | /** |
||
| 160 | * Transforms an object to an elastica document. |
||
| 161 | * |
||
| 162 | * @param object $object |
||
| 163 | * |
||
| 164 | * @return Document the elastica document |
||
| 165 | */ |
||
| 166 | 6 | public function transformToElasticaDocument($object) |
|
| 170 | |||
| 171 | /** |
||
| 172 | * Log exception if logger defined for persister belonging to the current listener, otherwise re-throw. |
||
| 173 | * |
||
| 174 | * @param BulkException $e |
||
| 175 | * |
||
| 176 | * @throws BulkException |
||
| 177 | */ |
||
| 178 | private function log(BulkException $e) |
||
| 186 | } |
||
| 187 |