Code Duplication    Length = 26-31 lines in 4 locations

src/voku/db/DB.php 4 locations

@@ 622-651 (lines=30) @@
619
     *
620
     * @return bool <p>This will return true or false indicating success of transaction</p>
621
     */
622
    public function beginTransaction(): bool
623
    {
624
        if ($this->in_transaction) {
625
            $this->debug->displayError('Error: mysql server already in transaction!', false);
626
627
            return false;
628
        }
629
630
        $this->clearErrors(); // needed for "$this->endTransaction()"
631
        $this->in_transaction = true;
632
633
        if ($this->mysqli_link) {
634
            $return = \mysqli_autocommit($this->mysqli_link, false);
635
        } elseif ($this->isDoctrinePDOConnection()) {
636
            $this->doctrine_connection->setAutoCommit(false);
637
            $this->doctrine_connection->beginTransaction();
638
639
            if ($this->doctrine_connection->isTransactionActive()) {
640
                $return = true;
641
            } else {
642
                $return = false;
643
            }
644
        }
645
646
        if (!$return) {
647
            $this->in_transaction = false;
648
        }
649
650
        return $return;
651
    }
652
653
    /**
654
     * Clear the errors in "_debug->_errors".
@@ 713-738 (lines=26) @@
710
     *
711
     * @return bool <p>bool true on success, false otherwise.</p>
712
     */
713
    public function commit(): bool
714
    {
715
        if (!$this->in_transaction) {
716
            $this->debug->displayError('Error: mysql server is not in transaction!', false);
717
718
            return false;
719
        }
720
721
        if ($this->mysqli_link) {
722
            $return = \mysqli_commit($this->mysqli_link);
723
            \mysqli_autocommit($this->mysqli_link, true);
724
        } elseif ($this->isDoctrinePDOConnection()) {
725
            $this->doctrine_connection->commit();
726
            $this->doctrine_connection->setAutoCommit(true);
727
728
            if ($this->doctrine_connection->isAutoCommit()) {
729
                $return = true;
730
            } else {
731
                $return = false;
732
            }
733
        }
734
735
        $this->in_transaction = false;
736
737
        return $return;
738
    }
739
740
    /**
741
     * Open a new connection to the MySQL server.
@@ 910-940 (lines=31) @@
907
     *
908
     * @return bool <p>This will return true or false indicating success of transactions.</p>
909
     */
910
    public function endTransaction(): bool
911
    {
912
        if (!$this->in_transaction) {
913
            $this->debug->displayError('Error: mysql server is not in transaction!', false);
914
915
            return false;
916
        }
917
918
        if (!$this->errors()) {
919
            $return = $this->commit();
920
        } else {
921
            $this->rollback();
922
            $return = false;
923
        }
924
925
        if ($this->mysqli_link) {
926
            \mysqli_autocommit($this->mysqli_link, true);
927
        } elseif ($this->isDoctrinePDOConnection()) {
928
            $this->doctrine_connection->setAutoCommit(true);
929
930
            if ($this->doctrine_connection->isAutoCommit()) {
931
                $return = true;
932
            } else {
933
                $return = false;
934
            }
935
        }
936
937
        $this->in_transaction = false;
938
939
        return $return;
940
    }
941
942
    /**
943
     * Get all errors from "$this->errors".
@@ 2075-2103 (lines=29) @@
2072
     *
2073
     * @return bool <p>bool true on success, false otherwise.</p>
2074
     */
2075
    public function rollback(): bool
2076
    {
2077
        if (!$this->in_transaction) {
2078
            $this->debug->displayError('Error: mysql server is not in transaction!', false);
2079
2080
            return false;
2081
        }
2082
2083
        // init
2084
        $return = false;
2085
2086
        if ($this->mysqli_link) {
2087
            $return = \mysqli_rollback($this->mysqli_link);
2088
            \mysqli_autocommit($this->mysqli_link, true);
2089
        } elseif ($this->isDoctrinePDOConnection()) {
2090
            $this->doctrine_connection->rollBack();
2091
            $this->doctrine_connection->setAutoCommit(true);
2092
2093
            if ($this->doctrine_connection->isAutoCommit()) {
2094
                $return = true;
2095
            } else {
2096
                $return = false;
2097
            }
2098
        }
2099
2100
        $this->in_transaction = false;
2101
2102
        return $return;
2103
    }
2104
2105
    /**
2106
     * Try to secure a variable, so can you use it in sql-queries.