Code Duplication    Length = 39-39 lines in 2 locations

src/DB.php 2 locations

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