Code Duplication    Length = 27-29 lines in 2 locations

src/Charcoal/Object/ObjectRevision.php 2 locations

@@ 390-416 (lines=27) @@
387
     * @param RevisionableInterface $obj The object  to load the last revision of.
388
     * @return ObjectRevision The last revision for the give object.
389
     */
390
    public function lastObjectRevision(RevisionableInterface $obj)
391
    {
392
        if ($this->source()->tableExists() === false) {
393
            $this->source()->createTable();
394
        }
395
396
        $rev = $this->modelFactory()->create(self::class);
397
398
        $sql = sprintf(
399
            'SELECT * FROM `%s` WHERE `target_type` = :target_type AND `target_id` = :target_id ORDER BY `rev_ts` DESC LIMIT 1',
400
            $this->source()->table()
401
        );
402
        $rev->loadFromQuery($sql, [
403
            'target_type' => $obj->objType(),
404
            'target_id'   => $obj->id(),
405
        ]);
406
407
        return $rev;
408
    }
409
410
    /**
411
     * Retrieve a specific object revision, by revision number.
412
     *
413
     * @param RevisionableInterface $obj    Target object.
414
     * @param integer               $revNum The revision number to load.
415
     * @return ObjectRevision
416
     */
417
    public function objectRevisionNum(RevisionableInterface $obj, $revNum)
418
    {
419
        if ($this->source()->tableExists() === false) {
@@ 417-445 (lines=29) @@
414
     * @param integer               $revNum The revision number to load.
415
     * @return ObjectRevision
416
     */
417
    public function objectRevisionNum(RevisionableInterface $obj, $revNum)
418
    {
419
        if ($this->source()->tableExists() === false) {
420
            $this->source()->createTable();
421
        }
422
423
        $rev = $this->modelFactory()->create(self::class);
424
425
        $sql = sprintf(
426
            'SELECT * FROM `%s` WHERE `target_type` = :target_type AND `target_id` = :target_id AND `rev_num` = :rev_num LIMIT 1',
427
            $this->source()->table()
428
        );
429
        $rev->loadFromQuery($sql, [
430
            'target_type' => $obj->objType(),
431
            'target_id'   => $obj->id(),
432
            'rev_num'     => intval($revNum),
433
        ]);
434
435
        return $rev;
436
    }
437
}
438