Code Duplication    Length = 39-39 lines in 2 locations

src/DB.php 2 locations

@@ 563-601 (lines=39) @@
560
     * @return bool If the insert was successful
561
     * @throws \Longman\TelegramBot\Exception\TelegramException
562
     */
563
    public static function insertInlineQueryRequest(InlineQuery $inline_query)
564
    {
565
        if (!self::isDbConnected()) {
566
            return false;
567
        }
568
569
        try {
570
            $sth = self::$pdo->prepare('
571
                INSERT IGNORE INTO `' . TB_INLINE_QUERY . '`
572
                (`id`, `user_id`, `location`, `query`, `offset`, `created_at`)
573
                VALUES
574
                (:inline_query_id, :user_id, :location, :query, :param_offset, :created_at)
575
            ');
576
577
            $date            = self::getTimestamp();
578
            $inline_query_id = $inline_query->getId();
579
            $from            = $inline_query->getFrom();
580
            $user_id         = null;
581
            if ($from instanceof User) {
582
                $user_id = $from->getId();
583
                self::insertUser($from, $date);
584
            }
585
586
            $location = $inline_query->getLocation();
587
            $query    = $inline_query->getQuery();
588
            $offset   = $inline_query->getOffset();
589
590
            $sth->bindParam(':inline_query_id', $inline_query_id, PDO::PARAM_INT);
591
            $sth->bindParam(':user_id', $user_id, PDO::PARAM_INT);
592
            $sth->bindParam(':location', $location, PDO::PARAM_STR);
593
            $sth->bindParam(':query', $query, PDO::PARAM_STR);
594
            $sth->bindParam(':param_offset', $offset, PDO::PARAM_STR);
595
            $sth->bindParam(':created_at', $date, PDO::PARAM_STR);
596
597
            return $sth->execute();
598
        } catch (PDOException $e) {
599
            throw new TelegramException($e->getMessage());
600
        }
601
    }
602
603
    /**
604
     * Insert chosen inline result request into database
@@ 611-649 (lines=39) @@
608
     * @return bool If the insert was successful
609
     * @throws \Longman\TelegramBot\Exception\TelegramException
610
     */
611
    public static function insertChosenInlineResultRequest(ChosenInlineResult $chosen_inline_result)
612
    {
613
        if (!self::isDbConnected()) {
614
            return false;
615
        }
616
617
        try {
618
            $sth = self::$pdo->prepare('
619
                INSERT INTO `' . TB_CHOSEN_INLINE_RESULT . '`
620
                (`result_id`, `user_id`, `location`, `inline_message_id`, `query`, `created_at`)
621
                VALUES
622
                (:result_id, :user_id, :location, :inline_message_id, :query, :created_at)
623
            ');
624
625
            $date      = self::getTimestamp();
626
            $result_id = $chosen_inline_result->getResultId();
627
            $from      = $chosen_inline_result->getFrom();
628
            $user_id   = null;
629
            if ($from instanceof User) {
630
                $user_id = $from->getId();
631
                self::insertUser($from, $date);
632
            }
633
634
            $location          = $chosen_inline_result->getLocation();
635
            $inline_message_id = $chosen_inline_result->getInlineMessageId();
636
            $query             = $chosen_inline_result->getQuery();
637
638
            $sth->bindParam(':result_id', $result_id, PDO::PARAM_STR);
639
            $sth->bindParam(':user_id', $user_id, PDO::PARAM_INT);
640
            $sth->bindParam(':location', $location, PDO::PARAM_STR);
641
            $sth->bindParam(':inline_message_id', $inline_message_id, PDO::PARAM_STR);
642
            $sth->bindParam(':query', $query, PDO::PARAM_STR);
643
            $sth->bindParam(':created_at', $date, PDO::PARAM_STR);
644
645
            return $sth->execute();
646
        } catch (PDOException $e) {
647
            throw new TelegramException($e->getMessage());
648
        }
649
    }
650
651
    /**
652
     * Insert callback query request into database