Code Duplication    Length = 39-39 lines in 2 locations

src/DB.php 2 locations

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