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 |
||
| 37 | abstract class QBMapper { |
||
| 38 | |||
| 39 | /** @var string */ |
||
| 40 | protected $tableName; |
||
| 41 | |||
| 42 | /** @var string */ |
||
| 43 | protected $entityClass; |
||
| 44 | |||
| 45 | /** @var IDBConnection */ |
||
| 46 | protected $db; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @param IDBConnection $db Instance of the Db abstraction layer |
||
| 50 | * @param string $tableName the name of the table. set this to allow entity |
||
| 51 | * @param string $entityClass the name of the entity that the sql should be |
||
| 52 | * mapped to queries without using sql |
||
| 53 | * @since 14.0.0 |
||
| 54 | */ |
||
| 55 | View Code Duplication | public function __construct(IDBConnection $db, string $tableName, string $entityClass=null){ |
|
| 67 | |||
| 68 | |||
| 69 | /** |
||
| 70 | * @return string the table name |
||
| 71 | * @since 14.0.0 |
||
| 72 | */ |
||
| 73 | public function getTableName(): string { |
||
| 76 | |||
| 77 | |||
| 78 | /** |
||
| 79 | * Deletes an entity from the table |
||
| 80 | * @param Entity $entity the entity that should be deleted |
||
| 81 | * @return Entity the deleted entity |
||
| 82 | * @since 14.0.0 |
||
| 83 | */ |
||
| 84 | View Code Duplication | public function delete(Entity $entity): Entity { |
|
| 94 | |||
| 95 | |||
| 96 | /** |
||
| 97 | * Creates a new entry in the db from an entity |
||
| 98 | * @param Entity $entity the entity that should be created |
||
| 99 | * @return Entity the saved entity with the set id |
||
| 100 | * @since 14.0.0 |
||
| 101 | * @suppress SqlInjectionChecker |
||
| 102 | */ |
||
| 103 | public function insert(Entity $entity): Entity { |
||
| 126 | |||
| 127 | /** |
||
| 128 | * Tries to creates a new entry in the db from an entity and |
||
| 129 | * updates an existing entry if duplicate keys are detected |
||
| 130 | * by the database |
||
| 131 | * |
||
| 132 | * @param Entity $entity the entity that should be created/updated |
||
| 133 | * @return Entity the saved entity with the (new) id |
||
| 134 | * @throws \InvalidArgumentException if entity has no id |
||
| 135 | * @since 15.0.0 |
||
| 136 | * @suppress SqlInjectionChecker |
||
| 137 | */ |
||
| 138 | public function insertOrUpdate(Entity $entity): Entity { |
||
| 145 | |||
| 146 | /** |
||
| 147 | * Updates an entry in the db from an entity |
||
| 148 | * @throws \InvalidArgumentException if entity has no id |
||
| 149 | * @param Entity $entity the entity that should be created |
||
| 150 | * @return Entity the saved entity with the set id |
||
| 151 | * @since 14.0.0 |
||
| 152 | * @suppress SqlInjectionChecker |
||
| 153 | */ |
||
| 154 | public function update(Entity $entity): Entity { |
||
| 192 | |||
| 193 | /** |
||
| 194 | * Returns an db result and throws exceptions when there are more or less |
||
| 195 | * results |
||
| 196 | * |
||
| 197 | * @see findEntity |
||
| 198 | * |
||
| 199 | * @param IQueryBuilder $query |
||
| 200 | * @throws DoesNotExistException if the item does not exist |
||
| 201 | * @throws MultipleObjectsReturnedException if more than one item exist |
||
| 202 | * @return array the result as row |
||
| 203 | * @since 14.0.0 |
||
| 204 | */ |
||
| 205 | protected function findOneQuery(IQueryBuilder $query): array { |
||
| 228 | |||
| 229 | /** |
||
| 230 | * @param string $msg |
||
| 231 | * @param IQueryBuilder $sql |
||
| 232 | * @return string |
||
| 233 | * @since 14.0.0 |
||
| 234 | */ |
||
| 235 | private function buildDebugMessage(string $msg, IQueryBuilder $sql): string { |
||
| 239 | |||
| 240 | |||
| 241 | /** |
||
| 242 | * Creates an entity from a row. Automatically determines the entity class |
||
| 243 | * from the current mapper name (MyEntityMapper -> MyEntity) |
||
| 244 | * |
||
| 245 | * @param array $row the row which should be converted to an entity |
||
| 246 | * @return Entity the entity |
||
| 247 | * @since 14.0.0 |
||
| 248 | */ |
||
| 249 | protected function mapRowToEntity(array $row): Entity { |
||
| 252 | |||
| 253 | |||
| 254 | /** |
||
| 255 | * Runs a sql query and returns an array of entities |
||
| 256 | * |
||
| 257 | * @param IQueryBuilder $query |
||
| 258 | * @return Entity[] all fetched entities |
||
| 259 | * @since 14.0.0 |
||
| 260 | */ |
||
| 261 | protected function findEntities(IQueryBuilder $query): array { |
||
| 274 | |||
| 275 | |||
| 276 | /** |
||
| 277 | * Returns an db result and throws exceptions when there are more or less |
||
| 278 | * results |
||
| 279 | * |
||
| 280 | * @param IQueryBuilder $query |
||
| 281 | * @throws DoesNotExistException if the item does not exist |
||
| 282 | * @throws MultipleObjectsReturnedException if more than one item exist |
||
| 283 | * @return Entity the entity |
||
| 284 | * @since 14.0.0 |
||
| 285 | */ |
||
| 286 | protected function findEntity(IQueryBuilder $query): Entity { |
||
| 289 | |||
| 290 | } |
||
| 291 |
Scrutinizer analyzes your
composer.json/composer.lockfile if available to determine the classes, and functions that are defined by your dependencies.It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.