Code Duplication    Length = 39-39 lines in 2 locations

src/DB.php 2 locations

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