Code Duplication    Length = 13-19 lines in 2 locations

src/TDBMService.php 2 locations

@@ 1246-1264 (lines=19) @@
1243
     *
1244
     * @throws TDBMException
1245
     */
1246
    public function findObject(string $mainTable, $filter = null, array $parameters = array(), array $additionalTablesFetch = array(), string $className = null)
1247
    {
1248
        $objects = $this->findObjects($mainTable, $filter, $parameters, null, $additionalTablesFetch, self::MODE_ARRAY, $className);
1249
        $page = $objects->take(0, 2);
1250
1251
1252
        $pageArr = $page->toArray();
1253
        // Optimisation: the $page->count() query can trigger an additional SQL query in platforms other than MySQL.
1254
        // We try to avoid calling at by fetching all 2 columns instead.
1255
        $count = count($pageArr);
1256
1257
        if ($count > 1) {
1258
            throw new DuplicateRowException("Error while querying an object for table '$mainTable': More than 1 row have been returned, but we should have received at most one.");
1259
        } elseif ($count === 0) {
1260
            return;
1261
        }
1262
1263
        return $pageArr[0];
1264
    }
1265
1266
    /**
1267
     * Returns a unique bean (or null) according to the filters passed in parameter.
@@ 1279-1291 (lines=13) @@
1276
     *
1277
     * @throws TDBMException
1278
     */
1279
    public function findObjectFromSql($mainTable, $from, $filter = null, array $parameters = array(), $className = null)
1280
    {
1281
        $objects = $this->findObjectsFromSql($mainTable, $from, $filter, $parameters, null, self::MODE_ARRAY, $className);
1282
        $page = $objects->take(0, 2);
1283
        $count = $page->count();
1284
        if ($count > 1) {
1285
            throw new DuplicateRowException("Error while querying an object for table '$mainTable': More than 1 row have been returned, but we should have received at most one.");
1286
        } elseif ($count === 0) {
1287
            return;
1288
        }
1289
1290
        return $page[0];
1291
    }
1292
1293
    /**
1294
     * @param string $mainTable