Code Duplication    Length = 39-39 lines in 2 locations

src/DB.php 2 locations

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