Code Duplication    Length = 35-35 lines in 2 locations

src/DB.php 2 locations

@@ 615-649 (lines=35) @@
612
     * @return bool If the insert was successful
613
     * @throws TelegramException
614
     */
615
    public static function insertInlineQueryRequest(InlineQuery $inline_query)
616
    {
617
        if (!self::isDbConnected()) {
618
            return false;
619
        }
620
621
        try {
622
            $sth = self::$pdo->prepare('
623
                INSERT IGNORE INTO `' . TB_INLINE_QUERY . '`
624
                (`id`, `user_id`, `location`, `query`, `offset`, `created_at`)
625
                VALUES
626
                (:id, :user_id, :location, :query, :offset, :created_at)
627
            ');
628
629
            $date    = self::getTimestamp();
630
            $user_id = null;
631
632
            $user = $inline_query->getFrom();
633
            if ($user instanceof User) {
634
                $user_id = $user->getId();
635
                self::insertUser($user, $date);
636
            }
637
638
            $sth->bindValue(':id', $inline_query->getId());
639
            $sth->bindValue(':user_id', $user_id);
640
            $sth->bindValue(':location', $inline_query->getLocation());
641
            $sth->bindValue(':query', $inline_query->getQuery());
642
            $sth->bindValue(':offset', $inline_query->getOffset());
643
            $sth->bindValue(':created_at', $date);
644
645
            return $sth->execute();
646
        } catch (PDOException $e) {
647
            throw new TelegramException($e->getMessage());
648
        }
649
    }
650
651
    /**
652
     * Insert chosen inline result request into database
@@ 659-693 (lines=35) @@
656
     * @return bool If the insert was successful
657
     * @throws TelegramException
658
     */
659
    public static function insertChosenInlineResultRequest(ChosenInlineResult $chosen_inline_result)
660
    {
661
        if (!self::isDbConnected()) {
662
            return false;
663
        }
664
665
        try {
666
            $sth = self::$pdo->prepare('
667
                INSERT INTO `' . TB_CHOSEN_INLINE_RESULT . '`
668
                (`result_id`, `user_id`, `location`, `inline_message_id`, `query`, `created_at`)
669
                VALUES
670
                (:result_id, :user_id, :location, :inline_message_id, :query, :created_at)
671
            ');
672
673
            $date    = self::getTimestamp();
674
            $user_id = null;
675
676
            $user = $chosen_inline_result->getFrom();
677
            if ($user instanceof User) {
678
                $user_id = $user->getId();
679
                self::insertUser($user, $date);
680
            }
681
682
            $sth->bindValue(':result_id', $chosen_inline_result->getResultId());
683
            $sth->bindValue(':user_id', $user_id);
684
            $sth->bindValue(':location', $chosen_inline_result->getLocation());
685
            $sth->bindValue(':inline_message_id', $chosen_inline_result->getInlineMessageId());
686
            $sth->bindValue(':query', $chosen_inline_result->getQuery());
687
            $sth->bindValue(':created_at', $date);
688
689
            return $sth->execute();
690
        } catch (PDOException $e) {
691
            throw new TelegramException($e->getMessage());
692
        }
693
    }
694
695
    /**
696
     * Insert callback query request into database