Code Duplication    Length = 28-32 lines in 3 locations

src/voku/db/DB.php 3 locations

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