<commit_before><?php

namespace CBase\Database\Mysql;

use \PDO;

/**
* Mysql class
*/
final class Mysql
{
    private $isConnect = false;
    private $pdo = null;

    private $rowCount = 0;
    private $sqlQuery = "";
    private $sqlResult = [];

    private $fetchModeArray = [
        'assoc' => PDO::FETCH_ASSOC,
        'both'    => PDO::FETCH_BOTH,
        'num'    => PDO::FETCH_NUM,
        'obj'    => PDO::FETCH_OBJ
    ];

    public function __construct(PDO $pdo)
    {
        return $this->connect($pdo);
    }

    public function isConnected()
    {
        return $this->isConnect;
    }

    public function connect(PDO $pdo)
    {
        if (!empty($pdo)) {
            $this->pdo = $pdo;
            $this->isConnect = true;
            return $pdo;
        }
        return false;
    }

    public function disconnect()
    {
        if (isset($this->isConnect)) {
            if (!is_string($this->sqlQuery) && $this->sqlQuery->closeCursor()) {
                $this->pdo = null;
                $this->isConnect = false;
                return true;
            } else {
                return false;
            }
        }
    }

    public function query($statement,  $fetchAll = true, $fetchMode = 'obj')
    {
        $this->sqlQuery =  $this->pdo
                                ->query($statement);

        if (isset($this->sqlQuery)) {
            $this->rowCount =  $this->sqlQuery
                                    ->rowCount();

            if (($fetchAll && $fetchMode === 'obj') || $this->isCUD($statement, ['INSERT', 'UPDATE', 'DELETE'])) {
                $this->sqlResult = $this->sqlQuery;

                return $this;
            }

            if ($fetchMode !== 'obj' && !array_key_exists($fetchMode, $this->fetchModeArray)) {
                $fetchMode = 'obj';
            }

            if ($fetchAll || !is_bool($fetchAll)) {
                $this->sqlResult = $this->sqlQuery
                                        ->fetchAll($this->fetchModeArray[$fetchMode]);
            } else {
                $this->sqlResult = $this->sqlQuery
                                        ->fetch($this->fetchModeArray[$fetchMode]);
            }

            return $this;
        }

        array_push($this->sqlResult, $this->pdo->errorInfo());
        return $this;
    }

    public function prepare($statement, array $attributes, $fetchAll = true, $fetchMode = 'obj')
    {
        $this->sqlQuery =  $this->pdo
                                ->prepare($statement);
        $executeResponse = $this->sqlQuery
                                ->execute($attributes);

        if (isset($this->sqlQuery)) {
            $this->rowCount =  $this->sqlQuery
                                    ->rowCount();

            if ($this->isCUD($statement, ['INSERT', 'UPDATE', 'DELETE'])) {
                return $executeResponse;
            }

            if ($fetchAll && $fetchMode === 'obj') {
                $this->sqlResult = $this->sqlQuery;

                return $this;
            }

            if ($fetchMode !== 'obj' && !array_key_exists($fetchMode, $this->fetchModeArray)) {
                $fetchMode = 'obj';
            }

            if ($fetchAll || !is_bool($fetchAll)) {
                $this->sqlResult = $this->sqlQuery
                                        ->fetchAll($this->fetchModeArray[$fetchMode]);
            } else {
                $this->sqlResult = $this->sqlQuery
                                        ->fetch($this->fetchModeArray[$fetchMode]);
            }

            return $this;
        }

        array_push($this->sqlResult, $this->pdo->errorInfo());
        return $this;
    }

    public function get()
    {
        return $this->sqlResult;
    }

    public function getRowCount()
    {
        return $this->rowCount;
    }

    public function getLastQuery()
    {
        return $this->sqlQuery;
    }

    public function getLastInsertId()
    {
        return $this->pdo
                    ->lastInsertId();
    }

    private function isCUD($statement, array $queryType)
    {
        foreach ($queryType as $type) {
            if (strpos($statement, $type) === 0) {
                return true;
            }
        }
        return false;
    }
}
<commit_msg>fix issue when result is boolean<commit_after><?php

namespace CBase\Database\Mysql;

use \PDO;

/**
* Mysql class
*/
final class Mysql
{
    private $isConnect = false;
    private $pdo = null;

    private $rowCount = 0;
    private $sqlQuery = "";
    private $sqlResult = [];

    private $fetchModeArray = [
        'assoc' => PDO::FETCH_ASSOC,
        'both'    => PDO::FETCH_BOTH,
        'num'    => PDO::FETCH_NUM,
        'obj'    => PDO::FETCH_OBJ
    ];

    public function __construct(PDO $pdo)
    {
        return $this->connect($pdo);
    }

    public function isConnected()
    {
        return $this->isConnect;
    }

    public function connect(PDO $pdo)
    {
        if (!empty($pdo)) {
            $this->pdo = $pdo;
            $this->isConnect = true;
            return $pdo;
        }
        return false;
    }

    public function disconnect()
    {
        if (isset($this->isConnect)) {
            if (!is_string($this->sqlQuery) && $this->sqlQuery->closeCursor()) {
                $this->pdo = null;
                $this->isConnect = false;
                return true;
            } else {
                return false;
            }
        }
    }

    public function query($statement,  $fetchAll = true, $fetchMode = 'obj')
    {
        $this->sqlQuery =  $this->pdo
                                ->query($statement);

        if (isset($this->sqlQuery) && !is_bool($this->sqlQuery)) {
            $this->rowCount =  $this->sqlQuery
                                    ->rowCount();

            if (($fetchAll && $fetchMode === 'obj') || $this->isCUD($statement, ['INSERT', 'UPDATE', 'DELETE'])) {
                $this->sqlResult = $this->sqlQuery;

                return $this;
            }

            if ($fetchMode !== 'obj' && !array_key_exists($fetchMode, $this->fetchModeArray)) {
                $fetchMode = 'obj';
            }

            if ($fetchAll || !is_bool($fetchAll)) {
                $this->sqlResult = $this->sqlQuery
                                        ->fetchAll($this->fetchModeArray[$fetchMode]);
            } else {
                $this->sqlResult = $this->sqlQuery
                                        ->fetch($this->fetchModeArray[$fetchMode]);
            }

            return $this;
        }

        array_push($this->sqlResult, $this->pdo->errorInfo());
        return $this;
    }

    public function prepare($statement, array $attributes, $fetchAll = true, $fetchMode = 'obj')
    {
        $this->sqlQuery =  $this->pdo
                                ->prepare($statement);
        $executeResponse = $this->sqlQuery
                                ->execute($attributes);

        if (isset($this->sqlQuery)) {
            $this->rowCount =  $this->sqlQuery
                                    ->rowCount();

            if ($this->isCUD($statement, ['INSERT', 'UPDATE', 'DELETE'])) {
                return $executeResponse;
            }

            if ($fetchAll && $fetchMode === 'obj') {
                $this->sqlResult = $this->sqlQuery;

                return $this;
            }

            if ($fetchMode !== 'obj' && !array_key_exists($fetchMode, $this->fetchModeArray)) {
                $fetchMode = 'obj';
            }

            if ($fetchAll || !is_bool($fetchAll)) {
                $this->sqlResult = $this->sqlQuery
                                        ->fetchAll($this->fetchModeArray[$fetchMode]);
            } else {
                $this->sqlResult = $this->sqlQuery
                                        ->fetch($this->fetchModeArray[$fetchMode]);
            }

            return $this;
        }

        array_push($this->sqlResult, $this->pdo->errorInfo());
        return $this;
    }

    public function get()
    {
        return $this->sqlResult;
    }

    public function getRowCount()
    {
        return $this->rowCount;
    }

    public function getLastQuery()
    {
        return $this->sqlQuery;
    }

    public function getLastInsertId()
    {
        return $this->pdo
                    ->lastInsertId();
    }

    private function isCUD($statement, array $queryType)
    {
        foreach ($queryType as $type) {
            if (strpos($statement, $type) === 0) {
                return true;
            }
        }
        return false;
    }
}

{'fraction_non_alphanumeric': 0.14215800512701002, 'fraction_numerical': 0.00046609182008855747, 'mean_word_length': 1.4143459915611813, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 134, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '491969', 'n_tokens_mistral': 2447, 'n_tokens_neox': 2326, 'n_words': 448}