Code Duplication    Length = 28-32 lines in 3 locations

src/voku/db/DB.php 3 locations

@@ 654-685 (lines=32) @@
651
     * @return bool
652
     *              <p>This will return true or false indicating success of transaction</p>
653
     */
654
    public function beginTransaction(): bool
655
    {
656
        if ($this->in_transaction) {
657
            $this->debug->displayError('Error: mysql server already in transaction!', false);
658
659
            return false;
660
        }
661
662
        $this->clearErrors(); // needed for "$this->endTransaction()"
663
        $this->in_transaction = true;
664
665
        if ($this->mysqli_link) {
666
            $return = \mysqli_autocommit($this->mysqli_link, false);
667
        } elseif ($this->doctrine_connection && $this->isDoctrinePDOConnection()) {
668
            $this->doctrine_connection->setAutoCommit(false);
669
            $this->doctrine_connection->beginTransaction();
670
671
            if ($this->doctrine_connection->isTransactionActive()) {
672
                $return = true;
673
            } else {
674
                $return = false;
675
            }
676
        } else {
677
            $return = false;
678
        }
679
680
        if (!$return) {
681
            $this->in_transaction = false;
682
        }
683
684
        return $return;
685
    }
686
687
    /**
688
     * Clear the errors in "_debug->_errors".
@@ 748-775 (lines=28) @@
745
     * @return bool
746
     *              <p>bool true on success, false otherwise.</p>
747
     */
748
    public function commit(): bool
749
    {
750
        if (!$this->in_transaction) {
751
            $this->debug->displayError('Error: mysql server is not in transaction!', false);
752
753
            return false;
754
        }
755
756
        if ($this->mysqli_link) {
757
            $return = \mysqli_commit($this->mysqli_link);
758
            \mysqli_autocommit($this->mysqli_link, true);
759
        } elseif ($this->doctrine_connection && $this->isDoctrinePDOConnection()) {
760
            $this->doctrine_connection->commit();
761
            $this->doctrine_connection->setAutoCommit(true);
762
763
            if ($this->doctrine_connection->isAutoCommit()) {
764
                $return = true;
765
            } else {
766
                $return = false;
767
            }
768
        } else {
769
            $return = false;
770
        }
771
772
        $this->in_transaction = false;
773
774
        return $return;
775
    }
776
777
    /**
778
     * Open a new connection to the MySQL server.
@@ 2180-2208 (lines=29) @@
2177
     * @return bool
2178
     *              <p>bool true on success, false otherwise.</p>
2179
     */
2180
    public function rollback(): bool
2181
    {
2182
        if (!$this->in_transaction) {
2183
            $this->debug->displayError('Error: mysql server is not in transaction!', false);
2184
2185
            return false;
2186
        }
2187
2188
        // init
2189
        $return = false;
2190
2191
        if ($this->mysqli_link) {
2192
            $return = \mysqli_rollback($this->mysqli_link);
2193
            \mysqli_autocommit($this->mysqli_link, true);
2194
        } elseif ($this->doctrine_connection && $this->isDoctrinePDOConnection()) {
2195
            $this->doctrine_connection->rollBack();
2196
            $this->doctrine_connection->setAutoCommit(true);
2197
2198
            if ($this->doctrine_connection->isAutoCommit()) {
2199
                $return = true;
2200
            } else {
2201
                $return = false;
2202
            }
2203
        }
2204
2205
        $this->in_transaction = false;
2206
2207
        return $return;
2208
    }
2209
2210
    /**
2211
     * Try to secure a variable, so can you use it in sql-queries.