Code Duplication    Length = 34-35 lines in 3 locations

src/DB.php 3 locations

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