Code Duplication    Length = 30-31 lines in 2 locations

src/voku/db/DB.php 2 locations

@@ 914-944 (lines=31) @@
911
     * @return false|int
912
     *                   <p>false on error</p>
913
     */
914
    public function delete(string $table, $where, string $databaseName = null)
915
    {
916
        // init
917
        $table = \trim($table);
918
919
        if ($table === '') {
920
            $this->debug->displayError('Invalid table name, table name in empty.', false);
921
922
            return false;
923
        }
924
925
        if (\is_string($where)) {
926
            $WHERE = $this->escape($where, false);
927
        } elseif (\is_array($where)) {
928
            $WHERE = $this->_parseArrayPair($where, 'AND');
929
        } else {
930
            $WHERE = '';
931
        }
932
933
        if ($databaseName) {
934
            $databaseName = $this->quote_string(\trim($databaseName)) . '.';
935
        }
936
937
        $sql = 'DELETE FROM ' . $databaseName . $this->quote_string($table) . " WHERE (${WHERE})";
938
939
        $return = $this->query($sql);
940
941
        \assert(\is_int($return) || $return === false);
942
943
        return $return;
944
    }
945
946
    /**
947
     * Ends a transaction and commits if no errors, then ends autocommit.
@@ 2305-2334 (lines=30) @@
2302
     * @return false|Result
2303
     *                      <p>false on error</p>
2304
     */
2305
    public function select(string $table, $where = '1=1', string $databaseName = null)
2306
    {
2307
        // init
2308
        $table = \trim($table);
2309
2310
        if ($table === '') {
2311
            $this->debug->displayError('Invalid table name, table name in empty.', false);
2312
2313
            return false;
2314
        }
2315
2316
        if (\is_string($where)) {
2317
            $WHERE = $this->escape($where, false);
2318
        } elseif (\is_array($where)) {
2319
            $WHERE = $this->_parseArrayPair($where, 'AND');
2320
        } else {
2321
            $WHERE = '';
2322
        }
2323
2324
        if ($databaseName) {
2325
            $databaseName = $this->quote_string(\trim($databaseName)) . '.';
2326
        }
2327
2328
        $sql = 'SELECT * FROM ' . $databaseName . $this->quote_string($table) . " WHERE (${WHERE})";
2329
2330
        $return = $this->query($sql);
2331
        \assert($return instanceof Result || $return === false);
2332
2333
        return $return;
2334
    }
2335
2336
    /**
2337
     * Selects a different database than the one specified on construction.