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 declare(strict_types=1); |
||
| 16 | final class Collection extends MongoCollection |
||
| 17 | { |
||
| 18 | /** @var EventDispatcherInterface */ |
||
| 19 | private $eventDispatcher; |
||
| 20 | /** @var string */ |
||
| 21 | private $clientName; |
||
| 22 | /** @var string */ |
||
| 23 | private $databaseName; |
||
|
|
|||
| 24 | |||
| 25 | /** |
||
| 26 | * Collection constructor. |
||
| 27 | * |
||
| 28 | * @param Manager $manager |
||
| 29 | * @param string $clientName |
||
| 30 | * @param string $databaseName |
||
| 31 | * @param string $collectionName |
||
| 32 | * @param array $options |
||
| 33 | * @param EventDispatcherInterface $eventDispatcher |
||
| 34 | * |
||
| 35 | * @internal param DataCollectorLoggerInterface $logger |
||
| 36 | */ |
||
| 37 | 15 | View Code Duplication | public function __construct( |
| 50 | |||
| 51 | /** |
||
| 52 | * {@inheritdoc} |
||
| 53 | */ |
||
| 54 | 1 | View Code Duplication | public function aggregate(array $pipeline, array $options = []) |
| 62 | |||
| 63 | /** |
||
| 64 | * {@inheritdoc} |
||
| 65 | */ |
||
| 66 | 1 | View Code Duplication | public function count($filter = [], array $options = []) |
| 74 | |||
| 75 | /** |
||
| 76 | * {@inheritdoc} |
||
| 77 | */ |
||
| 78 | 1 | View Code Duplication | public function find($filter = [], array $options = []) |
| 86 | |||
| 87 | /** |
||
| 88 | * {@inheritdoc} |
||
| 89 | */ |
||
| 90 | 1 | View Code Duplication | public function findOne($filter = [], array $options = []) |
| 98 | |||
| 99 | /** |
||
| 100 | * {@inheritdoc} |
||
| 101 | */ |
||
| 102 | 1 | View Code Duplication | public function findOneAndUpdate($filter, $update, array $options = []) |
| 110 | |||
| 111 | /** |
||
| 112 | * {@inheritdoc} |
||
| 113 | */ |
||
| 114 | 1 | View Code Duplication | public function findOneAndDelete($filter, array $options = []) |
| 122 | |||
| 123 | /** |
||
| 124 | * {@inheritdoc} |
||
| 125 | */ |
||
| 126 | 2 | View Code Duplication | public function deleteMany($filter, array $options = []) |
| 134 | |||
| 135 | /** |
||
| 136 | * {@inheritdoc} |
||
| 137 | */ |
||
| 138 | 1 | View Code Duplication | public function deleteOne($filter, array $options = []) |
| 146 | |||
| 147 | /** |
||
| 148 | * {@inheritdoc} |
||
| 149 | */ |
||
| 150 | 1 | View Code Duplication | public function replaceOne($filter, $replacement, array $options = []) |
| 158 | |||
| 159 | /** |
||
| 160 | * {@inheritdoc} |
||
| 161 | */ |
||
| 162 | 2 | View Code Duplication | public function insertOne($document, array $options = []) |
| 170 | |||
| 171 | /** |
||
| 172 | * {@inheritdoc} |
||
| 173 | */ |
||
| 174 | 1 | View Code Duplication | public function updateOne($filter, $update, array $options = []) |
| 182 | |||
| 183 | /** |
||
| 184 | * {@inheritdoc} |
||
| 185 | */ |
||
| 186 | 1 | View Code Duplication | public function distinct($fieldName, $filter = [], array $options = []) |
| 194 | |||
| 195 | /** |
||
| 196 | * @param string $method |
||
| 197 | * @param array|object $filters |
||
| 198 | * @param array|object $data |
||
| 199 | * @param array $options |
||
| 200 | * |
||
| 201 | * @return Query |
||
| 202 | */ |
||
| 203 | 12 | private function prepareQuery(string $method, $filters = null, $data = null, array $options): Query |
|
| 221 | |||
| 222 | /** |
||
| 223 | * @param ReadPreference $readPreference |
||
| 224 | * |
||
| 225 | * @return string |
||
| 226 | */ |
||
| 227 | 12 | private function translateReadPreference(ReadPreference $readPreference): string |
|
| 244 | |||
| 245 | /** |
||
| 246 | * @param Query $queryLog |
||
| 247 | * |
||
| 248 | * @return Query |
||
| 249 | */ |
||
| 250 | 12 | private function notifyQueryExecution(Query $queryLog) |
|
| 256 | |||
| 257 | /** |
||
| 258 | * @return string |
||
| 259 | */ |
||
| 260 | 12 | public function getClientName(): string |
|
| 264 | |||
| 265 | /** |
||
| 266 | * @return string |
||
| 267 | */ |
||
| 268 | 12 | public function getDatabaseName(): string |
|
| 272 | } |
||
| 273 | |||
| 274 |