Code Duplication    Length = 34-35 lines in 3 locations

src/DB.php 3 locations

@@ 582-616 (lines=35) @@
579
     * @return bool If the insert was successful
580
     * @throws TelegramException
581
     */
582
    public static function insertInlineQueryRequest(InlineQuery $inline_query)
583
    {
584
        if (!self::isDbConnected()) {
585
            return false;
586
        }
587
588
        try {
589
            $sth = self::$pdo->prepare('
590
                INSERT IGNORE INTO `' . TB_INLINE_QUERY . '`
591
                (`id`, `user_id`, `location`, `query`, `offset`, `created_at`)
592
                VALUES
593
                (:id, :user_id, :location, :query, :offset, :created_at)
594
            ');
595
596
            $date    = self::getTimestamp();
597
            $user_id = null;
598
599
            $user = $inline_query->getFrom();
600
            if ($user instanceof User) {
601
                $user_id = $user->getId();
602
                self::insertUser($user, $date);
603
            }
604
605
            $sth->bindValue(':id', $inline_query->getId());
606
            $sth->bindValue(':user_id', $user_id);
607
            $sth->bindValue(':location', $inline_query->getLocation());
608
            $sth->bindValue(':query', $inline_query->getQuery());
609
            $sth->bindValue(':offset', $inline_query->getOffset());
610
            $sth->bindValue(':created_at', $date);
611
612
            return $sth->execute();
613
        } catch (PDOException $e) {
614
            throw new TelegramException($e->getMessage());
615
        }
616
    }
617
618
    /**
619
     * Insert chosen inline result request into database
@@ 626-660 (lines=35) @@
623
     * @return bool If the insert was successful
624
     * @throws TelegramException
625
     */
626
    public static function insertChosenInlineResultRequest(ChosenInlineResult $chosen_inline_result)
627
    {
628
        if (!self::isDbConnected()) {
629
            return false;
630
        }
631
632
        try {
633
            $sth = self::$pdo->prepare('
634
                INSERT INTO `' . TB_CHOSEN_INLINE_RESULT . '`
635
                (`result_id`, `user_id`, `location`, `inline_message_id`, `query`, `created_at`)
636
                VALUES
637
                (:result_id, :user_id, :location, :inline_message_id, :query, :created_at)
638
            ');
639
640
            $date    = self::getTimestamp();
641
            $user_id = null;
642
643
            $user = $chosen_inline_result->getFrom();
644
            if ($user instanceof User) {
645
                $user_id = $user->getId();
646
                self::insertUser($user, $date);
647
            }
648
649
            $sth->bindValue(':result_id', $chosen_inline_result->getResultId());
650
            $sth->bindValue(':user_id', $user_id);
651
            $sth->bindValue(':location', $chosen_inline_result->getLocation());
652
            $sth->bindValue(':inline_message_id', $chosen_inline_result->getInlineMessageId());
653
            $sth->bindValue(':query', $chosen_inline_result->getQuery());
654
            $sth->bindValue(':created_at', $date);
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
@@ 739-772 (lines=34) @@
736
     * @return bool If the insert was successful
737
     * @throws TelegramException
738
     */
739
    public static function insertShippingQueryRequest(ShippingQuery $shipping_query)
740
    {
741
        if (!self::isDbConnected()) {
742
            return false;
743
        }
744
745
        try {
746
            $sth = self::$pdo->prepare('
747
                INSERT IGNORE INTO `' . TB_SHIPPING_QUERY . '`
748
                (`id`, `user_id`, `invoice_payload`, `shipping_address`, `created_at`)
749
                VALUES
750
                (:id, :user_id, :invoice_payload, :shipping_address, :created_at)
751
            ');
752
753
            $date    = self::getTimestamp();
754
            $user_id = null;
755
756
            $user = $shipping_query->getFrom();
757
            if ($user instanceof User) {
758
                $user_id = $user->getId();
759
                self::insertUser($user, $date);
760
            }
761
762
            $sth->bindValue(':id', $shipping_query->getId());
763
            $sth->bindValue(':user_id', $user_id);
764
            $sth->bindValue(':invoice_payload', $shipping_query->getInvoicePayload());
765
            $sth->bindValue(':shipping_address', $shipping_query->getShippingAddress());
766
            $sth->bindValue(':created_at', $date);
767
768
            return $sth->execute();
769
        } catch (PDOException $e) {
770
            throw new TelegramException($e->getMessage());
771
        }
772
    }
773
774
    /**
775
     * Insert pre checkout query request into database