Code Duplication    Length = 28-32 lines in 3 locations

src/voku/db/DB.php 3 locations

@@ 653-684 (lines=32) @@
650
     * @return bool
651
     *              <p>This will return true or false indicating success of transaction</p>
652
     */
653
    public function beginTransaction(): bool
654
    {
655
        if ($this->in_transaction) {
656
            $this->debug->displayError('Error: mysql server already in transaction!', false);
657
658
            return false;
659
        }
660
661
        $this->clearErrors(); // needed for "$this->endTransaction()"
662
        $this->in_transaction = true;
663
664
        if ($this->mysqli_link) {
665
            $return = \mysqli_autocommit($this->mysqli_link, false);
666
        } elseif ($this->doctrine_connection && $this->isDoctrinePDOConnection()) {
667
            $this->doctrine_connection->setAutoCommit(false);
668
            $this->doctrine_connection->beginTransaction();
669
670
            if ($this->doctrine_connection->isTransactionActive()) {
671
                $return = true;
672
            } else {
673
                $return = false;
674
            }
675
        } else {
676
            $return = false;
677
        }
678
679
        if (!$return) {
680
            $this->in_transaction = false;
681
        }
682
683
        return $return;
684
    }
685
686
    /**
687
     * Clear the errors in "_debug->_errors".
@@ 747-774 (lines=28) @@
744
     * @return bool
745
     *              <p>bool true on success, false otherwise.</p>
746
     */
747
    public function commit(): bool
748
    {
749
        if (!$this->in_transaction) {
750
            $this->debug->displayError('Error: mysql server is not in transaction!', false);
751
752
            return false;
753
        }
754
755
        if ($this->mysqli_link) {
756
            $return = \mysqli_commit($this->mysqli_link);
757
            \mysqli_autocommit($this->mysqli_link, true);
758
        } elseif ($this->doctrine_connection && $this->isDoctrinePDOConnection()) {
759
            $this->doctrine_connection->commit();
760
            $this->doctrine_connection->setAutoCommit(true);
761
762
            if ($this->doctrine_connection->isAutoCommit()) {
763
                $return = true;
764
            } else {
765
                $return = false;
766
            }
767
        } else {
768
            $return = false;
769
        }
770
771
        $this->in_transaction = false;
772
773
        return $return;
774
    }
775
776
    /**
777
     * Open a new connection to the MySQL server.
@@ 2150-2178 (lines=29) @@
2147
     * @return bool
2148
     *              <p>bool true on success, false otherwise.</p>
2149
     */
2150
    public function rollback(): bool
2151
    {
2152
        if (!$this->in_transaction) {
2153
            $this->debug->displayError('Error: mysql server is not in transaction!', false);
2154
2155
            return false;
2156
        }
2157
2158
        // init
2159
        $return = false;
2160
2161
        if ($this->mysqli_link) {
2162
            $return = \mysqli_rollback($this->mysqli_link);
2163
            \mysqli_autocommit($this->mysqli_link, true);
2164
        } elseif ($this->doctrine_connection && $this->isDoctrinePDOConnection()) {
2165
            $this->doctrine_connection->rollBack();
2166
            $this->doctrine_connection->setAutoCommit(true);
2167
2168
            if ($this->doctrine_connection->isAutoCommit()) {
2169
                $return = true;
2170
            } else {
2171
                $return = false;
2172
            }
2173
        }
2174
2175
        $this->in_transaction = false;
2176
2177
        return $return;
2178
    }
2179
2180
    /**
2181
     * Try to secure a variable, so can you use it in sql-queries.