Code Duplication    Length = 39-39 lines in 2 locations

src/DB.php 2 locations

@@ 590-628 (lines=39) @@
587
     * @return bool If the insert was successful
588
     * @throws \Longman\TelegramBot\Exception\TelegramException
589
     */
590
    public static function insertInlineQueryRequest(InlineQuery $inline_query)
591
    {
592
        if (!self::isDbConnected()) {
593
            return false;
594
        }
595
596
        try {
597
            $sth = self::$pdo->prepare('
598
                INSERT IGNORE INTO `' . TB_INLINE_QUERY . '`
599
                (`id`, `user_id`, `location`, `query`, `offset`, `created_at`)
600
                VALUES
601
                (:inline_query_id, :user_id, :location, :query, :param_offset, :created_at)
602
            ');
603
604
            $date            = self::getTimestamp();
605
            $inline_query_id = $inline_query->getId();
606
            $from            = $inline_query->getFrom();
607
            $user_id         = null;
608
            if ($from instanceof User) {
609
                $user_id = $from->getId();
610
                self::insertUser($from, $date);
611
            }
612
613
            $location = $inline_query->getLocation();
614
            $query    = $inline_query->getQuery();
615
            $offset   = $inline_query->getOffset();
616
617
            $sth->bindParam(':inline_query_id', $inline_query_id, PDO::PARAM_INT);
618
            $sth->bindParam(':user_id', $user_id, PDO::PARAM_INT);
619
            $sth->bindParam(':location', $location, PDO::PARAM_STR);
620
            $sth->bindParam(':query', $query, PDO::PARAM_STR);
621
            $sth->bindParam(':param_offset', $offset, PDO::PARAM_STR);
622
            $sth->bindParam(':created_at', $date, PDO::PARAM_STR);
623
624
            return $sth->execute();
625
        } catch (PDOException $e) {
626
            throw new TelegramException($e->getMessage());
627
        }
628
    }
629
630
    /**
631
     * Insert chosen inline result request into database
@@ 638-676 (lines=39) @@
635
     * @return bool If the insert was successful
636
     * @throws \Longman\TelegramBot\Exception\TelegramException
637
     */
638
    public static function insertChosenInlineResultRequest(ChosenInlineResult $chosen_inline_result)
639
    {
640
        if (!self::isDbConnected()) {
641
            return false;
642
        }
643
644
        try {
645
            $sth = self::$pdo->prepare('
646
                INSERT INTO `' . TB_CHOSEN_INLINE_RESULT . '`
647
                (`result_id`, `user_id`, `location`, `inline_message_id`, `query`, `created_at`)
648
                VALUES
649
                (:result_id, :user_id, :location, :inline_message_id, :query, :created_at)
650
            ');
651
652
            $date      = self::getTimestamp();
653
            $result_id = $chosen_inline_result->getResultId();
654
            $from      = $chosen_inline_result->getFrom();
655
            $user_id   = null;
656
            if ($from instanceof User) {
657
                $user_id = $from->getId();
658
                self::insertUser($from, $date);
659
            }
660
661
            $location          = $chosen_inline_result->getLocation();
662
            $inline_message_id = $chosen_inline_result->getInlineMessageId();
663
            $query             = $chosen_inline_result->getQuery();
664
665
            $sth->bindParam(':result_id', $result_id, PDO::PARAM_STR);
666
            $sth->bindParam(':user_id', $user_id, PDO::PARAM_INT);
667
            $sth->bindParam(':location', $location, PDO::PARAM_STR);
668
            $sth->bindParam(':inline_message_id', $inline_message_id, PDO::PARAM_STR);
669
            $sth->bindParam(':query', $query, PDO::PARAM_STR);
670
            $sth->bindParam(':created_at', $date, PDO::PARAM_STR);
671
672
            return $sth->execute();
673
        } catch (PDOException $e) {
674
            throw new TelegramException($e->getMessage());
675
        }
676
    }
677
678
    /**
679
     * Insert callback query request into database