Code Duplication    Length = 28-31 lines in 3 locations

src/voku/db/DB.php 3 locations

@@ 643-673 (lines=31) @@
640
     * @return bool
641
     *              <p>This will return true or false indicating success of transaction</p>
642
     */
643
    public function beginTransaction(): bool
644
    {
645
        if ($this->in_transaction) {
646
            $this->debug->displayError('Error: mysql server already in transaction!', false);
647
648
            return false;
649
        }
650
651
        $this->clearErrors(); // needed for "$this->endTransaction()"
652
        $this->in_transaction = true;
653
654
        if ($this->mysqli_link) {
655
            $return = \mysqli_autocommit($this->mysqli_link, false);
656
        } elseif ($this->doctrine_connection && $this->isDoctrinePDOConnection()) {
657
            $this->doctrine_connection->setAutoCommit(false);
658
659
            if ($this->doctrine_connection->isTransactionActive()) {
660
                $return = true;
661
            } else {
662
                $return = false;
663
            }
664
        } else {
665
            $return = false;
666
        }
667
668
        if (!$return) {
669
            $this->in_transaction = false;
670
        }
671
672
        return $return;
673
    }
674
675
    /**
676
     * Clear the errors in "_debug->_errors".
@@ 738-765 (lines=28) @@
735
     * @return bool
736
     *              <p>bool true on success, false otherwise.</p>
737
     */
738
    public function commit(): bool
739
    {
740
        if (!$this->in_transaction) {
741
            $this->debug->displayError('Error: mysql server is not in transaction!', false);
742
743
            return false;
744
        }
745
746
        if ($this->mysqli_link) {
747
            $return = \mysqli_commit($this->mysqli_link);
748
            \mysqli_autocommit($this->mysqli_link, true);
749
        } elseif ($this->doctrine_connection && $this->isDoctrinePDOConnection()) {
750
            $this->doctrine_connection->commit();
751
            $this->doctrine_connection->setAutoCommit(true);
752
753
            if ($this->doctrine_connection->isAutoCommit()) {
754
                $return = true;
755
            } else {
756
                $return = false;
757
            }
758
        } else {
759
            $return = false;
760
        }
761
762
        $this->in_transaction = false;
763
764
        return $return;
765
    }
766
767
    /**
768
     * Open a new connection to the MySQL server.
@@ 2213-2241 (lines=29) @@
2210
     * @return bool
2211
     *              <p>bool true on success, false otherwise.</p>
2212
     */
2213
    public function rollback(): bool
2214
    {
2215
        if (!$this->in_transaction) {
2216
            $this->debug->displayError('Error: mysql server is not in transaction!', false);
2217
2218
            return false;
2219
        }
2220
2221
        // init
2222
        $return = false;
2223
2224
        if ($this->mysqli_link) {
2225
            $return = \mysqli_rollback($this->mysqli_link);
2226
            \mysqli_autocommit($this->mysqli_link, true);
2227
        } elseif ($this->doctrine_connection && $this->isDoctrinePDOConnection()) {
2228
            $this->doctrine_connection->rollBack();
2229
            $this->doctrine_connection->setAutoCommit(true);
2230
2231
            if ($this->doctrine_connection->isAutoCommit()) {
2232
                $return = true;
2233
            } else {
2234
                $return = false;
2235
            }
2236
        }
2237
2238
        $this->in_transaction = false;
2239
2240
        return $return;
2241
    }
2242
2243
    /**
2244
     * Try to secure a variable, so can you use it in sql-queries.