Code Duplication    Length = 39-39 lines in 2 locations

src/DB.php 2 locations

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