Code Duplication    Length = 28-32 lines in 3 locations

src/voku/db/DB.php 3 locations

@@ 633-664 (lines=32) @@
630
     * @return bool
631
     *              <p>This will return true or false indicating success of transaction</p>
632
     */
633
    public function beginTransaction(): bool
634
    {
635
        if ($this->in_transaction) {
636
            $this->debug->displayError('Error: mysql server already in transaction!', false);
637
638
            return false;
639
        }
640
641
        $this->clearErrors(); // needed for "$this->endTransaction()"
642
        $this->in_transaction = true;
643
644
        if ($this->mysqli_link) {
645
            $return = \mysqli_autocommit($this->mysqli_link, false);
646
        } elseif ($this->doctrine_connection && $this->isDoctrinePDOConnection()) {
647
            $this->doctrine_connection->setAutoCommit(false);
648
            $this->doctrine_connection->beginTransaction();
649
650
            if ($this->doctrine_connection->isTransactionActive()) {
651
                $return = true;
652
            } else {
653
                $return = false;
654
            }
655
        } else {
656
            $return = false;
657
        }
658
659
        if (!$return) {
660
            $this->in_transaction = false;
661
        }
662
663
        return $return;
664
    }
665
666
    /**
667
     * Clear the errors in "_debug->_errors".
@@ 727-754 (lines=28) @@
724
     * @return bool
725
     *              <p>bool true on success, false otherwise.</p>
726
     */
727
    public function commit(): bool
728
    {
729
        if (!$this->in_transaction) {
730
            $this->debug->displayError('Error: mysql server is not in transaction!', false);
731
732
            return false;
733
        }
734
735
        if ($this->mysqli_link) {
736
            $return = \mysqli_commit($this->mysqli_link);
737
            \mysqli_autocommit($this->mysqli_link, true);
738
        } elseif ($this->doctrine_connection && $this->isDoctrinePDOConnection()) {
739
            $this->doctrine_connection->commit();
740
            $this->doctrine_connection->setAutoCommit(true);
741
742
            if ($this->doctrine_connection->isAutoCommit()) {
743
                $return = true;
744
            } else {
745
                $return = false;
746
            }
747
        } else {
748
            $return = false;
749
        }
750
751
        $this->in_transaction = false;
752
753
        return $return;
754
    }
755
756
    /**
757
     * Open a new connection to the MySQL server.
@@ 2135-2163 (lines=29) @@
2132
     * @return bool
2133
     *              <p>bool true on success, false otherwise.</p>
2134
     */
2135
    public function rollback(): bool
2136
    {
2137
        if (!$this->in_transaction) {
2138
            $this->debug->displayError('Error: mysql server is not in transaction!', false);
2139
2140
            return false;
2141
        }
2142
2143
        // init
2144
        $return = false;
2145
2146
        if ($this->mysqli_link) {
2147
            $return = \mysqli_rollback($this->mysqli_link);
2148
            \mysqli_autocommit($this->mysqli_link, true);
2149
        } elseif ($this->doctrine_connection && $this->isDoctrinePDOConnection()) {
2150
            $this->doctrine_connection->rollBack();
2151
            $this->doctrine_connection->setAutoCommit(true);
2152
2153
            if ($this->doctrine_connection->isAutoCommit()) {
2154
                $return = true;
2155
            } else {
2156
                $return = false;
2157
            }
2158
        }
2159
2160
        $this->in_transaction = false;
2161
2162
        return $return;
2163
    }
2164
2165
    /**
2166
     * Try to secure a variable, so can you use it in sql-queries.