Code Duplication    Length = 42-42 lines in 2 locations

src/DB.php 2 locations

@@ 510-551 (lines=42) @@
507
     * @return bool If the insert was successful
508
     * @throws \Longman\TelegramBot\Exception\TelegramException
509
     */
510
    public static function insertInlineQueryRequest(InlineQuery $inline_query)
511
    {
512
        if (!self::isDbConnected()) {
513
            return false;
514
        }
515
516
        try {
517
            $mysql_query = 'INSERT IGNORE INTO `' . TB_INLINE_QUERY . '`
518
                (
519
                `id`, `user_id`, `location`, `query`, `offset`, `created_at`
520
                )
521
                VALUES (
522
                :inline_query_id, :user_id, :location, :query, :param_offset, :created_at
523
                )';
524
525
            $sth_insert_inline_query = self::$pdo->prepare($mysql_query);
526
527
            $date            = self::getTimestamp(time());
528
            $inline_query_id = $inline_query->getId();
529
            $from            = $inline_query->getFrom();
530
            $user_id         = null;
531
            if (is_object($from)) {
532
                $user_id = $from->getId();
533
                self::insertUser($from, $date);
534
            }
535
536
            $location = $inline_query->getLocation();
537
            $query    = $inline_query->getQuery();
538
            $offset   = $inline_query->getOffset();
539
540
            $sth_insert_inline_query->bindParam(':inline_query_id', $inline_query_id, PDO::PARAM_INT);
541
            $sth_insert_inline_query->bindParam(':user_id', $user_id, PDO::PARAM_INT);
542
            $sth_insert_inline_query->bindParam(':location', $location, PDO::PARAM_STR);
543
            $sth_insert_inline_query->bindParam(':query', $query, PDO::PARAM_STR);
544
            $sth_insert_inline_query->bindParam(':param_offset', $offset, PDO::PARAM_STR);
545
            $sth_insert_inline_query->bindParam(':created_at', $date, PDO::PARAM_STR);
546
547
            return $sth_insert_inline_query->execute();
548
        } catch (PDOException $e) {
549
            throw new TelegramException($e->getMessage());
550
        }
551
    }
552
553
    /**
554
     * Insert chosen inline result request into database
@@ 561-602 (lines=42) @@
558
     * @return bool If the insert was successful
559
     * @throws \Longman\TelegramBot\Exception\TelegramException
560
     */
561
    public static function insertChosenInlineResultRequest(ChosenInlineResult $chosen_inline_result)
562
    {
563
        if (!self::isDbConnected()) {
564
            return false;
565
        }
566
567
        try {
568
            $mysql_query = 'INSERT INTO `' . TB_CHOSEN_INLINE_RESULT . '`
569
                    (
570
                    `result_id`, `user_id`, `location`, `inline_message_id`, `query`, `created_at`
571
                    )
572
                    VALUES (
573
                    :result_id, :user_id, :location, :inline_message_id, :query, :created_at
574
                    )';
575
576
            $sth_insert_chosen_inline_result = self::$pdo->prepare($mysql_query);
577
578
            $date      = self::getTimestamp(time());
579
            $result_id = $chosen_inline_result->getResultId();
580
            $from      = $chosen_inline_result->getFrom();
581
            $user_id   = null;
582
            if (is_object($from)) {
583
                $user_id = $from->getId();
584
                self::insertUser($from, $date);
585
            }
586
587
            $location          = $chosen_inline_result->getLocation();
588
            $inline_message_id = $chosen_inline_result->getInlineMessageId();
589
            $query             = $chosen_inline_result->getQuery();
590
591
            $sth_insert_chosen_inline_result->bindParam(':result_id', $result_id, PDO::PARAM_STR);
592
            $sth_insert_chosen_inline_result->bindParam(':user_id', $user_id, PDO::PARAM_INT);
593
            $sth_insert_chosen_inline_result->bindParam(':location', $location, PDO::PARAM_INT);
594
            $sth_insert_chosen_inline_result->bindParam(':inline_message_id', $inline_message_id, PDO::PARAM_STR);
595
            $sth_insert_chosen_inline_result->bindParam(':query', $query, PDO::PARAM_STR);
596
            $sth_insert_chosen_inline_result->bindParam(':created_at', $date, PDO::PARAM_STR);
597
598
            return $sth_insert_chosen_inline_result->execute();
599
        } catch (PDOException $e) {
600
            throw new TelegramException($e->getMessage());
601
        }
602
    }
603
604
    /**
605
     * Insert callback query request into database