Code Duplication    Length = 39-39 lines in 2 locations

src/DB.php 2 locations

@@ 532-570 (lines=39) @@
529
     * @return bool If the insert was successful
530
     * @throws \Longman\TelegramBot\Exception\TelegramException
531
     */
532
    public static function insertInlineQueryRequest(InlineQuery $inline_query)
533
    {
534
        if (!self::isDbConnected()) {
535
            return false;
536
        }
537
538
        try {
539
            $sth = self::$pdo->prepare('
540
                INSERT IGNORE INTO `' . TB_INLINE_QUERY . '`
541
                (`id`, `user_id`, `location`, `query`, `offset`, `created_at`)
542
                VALUES
543
                (:inline_query_id, :user_id, :location, :query, :param_offset, :created_at)
544
            ');
545
546
            $date            = self::getTimestamp();
547
            $inline_query_id = $inline_query->getId();
548
            $from            = $inline_query->getFrom();
549
            $user_id         = null;
550
            if ($from instanceof User) {
551
                $user_id = $from->getId();
552
                self::insertUser($from, $date);
553
            }
554
555
            $location = $inline_query->getLocation();
556
            $query    = $inline_query->getQuery();
557
            $offset   = $inline_query->getOffset();
558
559
            $sth->bindParam(':inline_query_id', $inline_query_id, PDO::PARAM_INT);
560
            $sth->bindParam(':user_id', $user_id, PDO::PARAM_INT);
561
            $sth->bindParam(':location', $location, PDO::PARAM_STR);
562
            $sth->bindParam(':query', $query, PDO::PARAM_STR);
563
            $sth->bindParam(':param_offset', $offset, PDO::PARAM_STR);
564
            $sth->bindParam(':created_at', $date, PDO::PARAM_STR);
565
566
            return $sth->execute();
567
        } catch (PDOException $e) {
568
            throw new TelegramException($e->getMessage());
569
        }
570
    }
571
572
    /**
573
     * Insert chosen inline result request into database
@@ 580-618 (lines=39) @@
577
     * @return bool If the insert was successful
578
     * @throws \Longman\TelegramBot\Exception\TelegramException
579
     */
580
    public static function insertChosenInlineResultRequest(ChosenInlineResult $chosen_inline_result)
581
    {
582
        if (!self::isDbConnected()) {
583
            return false;
584
        }
585
586
        try {
587
            $sth = self::$pdo->prepare('
588
                INSERT INTO `' . TB_CHOSEN_INLINE_RESULT . '`
589
                (`result_id`, `user_id`, `location`, `inline_message_id`, `query`, `created_at`)
590
                VALUES
591
                (:result_id, :user_id, :location, :inline_message_id, :query, :created_at)
592
            ');
593
594
            $date      = self::getTimestamp();
595
            $result_id = $chosen_inline_result->getResultId();
596
            $from      = $chosen_inline_result->getFrom();
597
            $user_id   = null;
598
            if ($from instanceof User) {
599
                $user_id = $from->getId();
600
                self::insertUser($from, $date);
601
            }
602
603
            $location          = $chosen_inline_result->getLocation();
604
            $inline_message_id = $chosen_inline_result->getInlineMessageId();
605
            $query             = $chosen_inline_result->getQuery();
606
607
            $sth->bindParam(':result_id', $result_id, PDO::PARAM_STR);
608
            $sth->bindParam(':user_id', $user_id, PDO::PARAM_INT);
609
            $sth->bindParam(':location', $location, PDO::PARAM_INT);
610
            $sth->bindParam(':inline_message_id', $inline_message_id, PDO::PARAM_STR);
611
            $sth->bindParam(':query', $query, PDO::PARAM_STR);
612
            $sth->bindParam(':created_at', $date, PDO::PARAM_STR);
613
614
            return $sth->execute();
615
        } catch (PDOException $e) {
616
            throw new TelegramException($e->getMessage());
617
        }
618
    }
619
620
    /**
621
     * Insert callback query request into database