Code Duplication    Length = 34-35 lines in 3 locations

src/DB.php 3 locations

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