Code Duplication    Length = 39-39 lines in 2 locations

src/DB.php 2 locations

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