<commit_before><?php

class CM_Db_Client {

    /** @var string */
    private $_host;

    /** @var int */
    private $_port;

    /** @var string */
    private $_username;

    /** @var string */
    private $_password;

    /** @var string|null */
    private $_db;

    /** @var PDO|null */
    private $_pdo;

    /** @var int */
    private $_lastConnect;

    /** @var int|null */
    private $_reconnectTimeout;

    /**
     * @param mixed[]    $config {
     * @type string      $host
     * @type int         $port
     * @type string      $username
     * @type string      $password
     * @type string|null $db
     * @type int|null    $reconnectTimeout
     *                           }
     */
    public function __construct(array $config) {
        $this->_host = (string) $config['host'];
        $this->_port = (int) $config['port'];
        $this->_username = (string) $config['username'];
        $this->_password = (string) $config['password'];
        if (isset($config['db'])) {
            $this->_db = (string) $config['db'];
        }
        if (isset($config['reconnectTimeout'])) {
            $this->_reconnectTimeout = (int) $config['reconnectTimeout'];
        }
    }

    /**
     * @throws CM_Db_Exception
     */
    public function connect() {
        if ($this->isConnected()) {
            return;
        }
        $dsnOptions = array('host=' . $this->_host, 'port=' . $this->_port);
        if (null !== $this->_db) {
            $dsnOptions[] = 'dbname=' . $this->_db;
        }
        $dsn = 'mysql:' . implode(';', $dsnOptions);
        try {
            $time = microtime(true) * 1000;
            $this->_pdo = new PDO($dsn, $this->_username, $this->_password, array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES "UTF8"'));
            CMService_Newrelic::getInstance()->setCustomMetric('DB connect', (microtime(true) * 1000) - $time);
            $this->_pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        } catch (PDOException $e) {
            throw new CM_Db_Exception('Database connection failed: ' . $e->getMessage());
        }
        $this->_lastConnect = time();
    }

    public function disconnect() {
        if (!$this->isConnected()) {
            return;
        }
        unset($this->_pdo);
    }

    /**
     * @return bool
     */
    public function isConnected() {
        return isset($this->_pdo);
    }

    /**
     * @return mixed[] {
     * @type string      $host
     * @type int         $port
     * @type string      $username
     * @type string      $password
     * @type string|null $db
     * @type int|null    $reconnectTimeout
     *                 }
     */
    public function getConfig() {
        return array(
            'host'             => $this->getHost(),
            'port'             => $this->getPort(),
            'username'         => $this->getUsername(),
            'password'         => $<PASSWORD>(),
            'db' => $this->getDatabaseName(),
            'reconnectTimeout' => $this->getReconnectTimeout(),
        );
    }

    /**
     * @return string|null
     */
    public function getDatabaseName() {
        return $this->_db;<commit_msg>Formatting<commit_after><?php

class CM_Db_Client {

    /** @var string */
    private $_host;

    /** @var int */
    private $_port;

    /** @var string */
    private $_username;

    /** @var string */
    private $_password;

    /** @var string|null */
    private $_db;

    /** @var PDO|null */
    private $_pdo;

    /** @var int */
    private $_lastConnect;

    /** @var int|null */
    private $_reconnectTimeout;

    /**
     * @param mixed[]    $config {
     * @type string      $host
     * @type int         $port
     * @type string      $username
     * @type string      $password
     * @type string|null $db
     * @type int|null    $reconnectTimeout
     *                           }
     */
    public function __construct(array $config) {
        $this->_host = (string) $config['host'];
        $this->_port = (int) $config['port'];
        $this->_username = (string) $config['username'];
        $this->_password = (string) $config['password'];
        if (isset($config['db'])) {
            $this->_db = (string) $config['db'];
        }
        if (isset($config['reconnectTimeout'])) {
            $this->_reconnectTimeout = (int) $config['reconnectTimeout'];
        }
    }

    /**
     * @throws CM_Db_Exception
     */
    public function connect() {
        if ($this->isConnected()) {
            return;
        }
        $dsnOptions = array('host=' . $this->_host, 'port=' . $this->_port);
        if (null !== $this->_db) {
            $dsnOptions[] = 'dbname=' . $this->_db;
        }
        $dsn = 'mysql:' . implode(';', $dsnOptions);
        try {
            $time = microtime(true) * 1000;
            $this->_pdo = new PDO($dsn, $this->_username, $this->_password, array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES "UTF8"'));
            CMService_Newrelic::getInstance()->setCustomMetric('DB connect', (microtime(true) * 1000) - $time);
            $this->_pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        } catch (PDOException $e) {
            throw new CM_Db_Exception('Database connection failed: ' . $e->getMessage());
        }
        $this->_lastConnect = time();
    }

    public function disconnect() {
        if (!$this->isConnected()) {
            return;
        }
        unset($this->_pdo);
    }

    /**
     * @return bool
     */
    public function isConnected() {
        return isset($this->_pdo);
    }

    /**
     * @return mixed[] {
     * @type string      $host
     * @type int         $port
     * @type string      $username
     * @type string      $password
     * @type string|null $db
     * @type int|null    $reconnectTimeout
     *                 }
     */
    public function getConfig() {
        return array(
            'host'             => $this->getHost(),
            'port'             => $this->getPort(),
            'username'         => $this->getUsername(),
            'password'         => $<PASSWORD>(),
            'db'               => $this->getDatabaseName(),
            'reconnectTimeout' => $this->getReconnectTimeout(),
        );
    }

    /**
     * @return string|null
     */
    public function getDatabaseName() {
        return $this->_db;
{'fraction_non_alphanumeric': 0.16465422612513722, 'fraction_numerical': 0.0028226438764309236, 'mean_word_length': 1.7550755939524838, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 75, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7115899', 'n_tokens_mistral': 1907, 'n_tokens_neox': 1865, 'n_words': 387}