<commit_before><?php

/**
 * PHPAuth config class
 */
class Config
{
    private $dbh;
    private $config;
    private $phpauth_config_table = 'config';

    /**
     * Construct Config class, that contains all configuration values.
     * 
     * It is a little trick: we can call '$config = new Config($dbh, "config_table");' always or
     * we can patch private $phpauth_config_table manually and calls '$config = new Config($dbh);'
     * without any additional values!
     * @param \PDO $dbh             -- PDO database connect handler
     * @param string $config_table  -- config table name
     */
    public function __construct(\PDO $dbh, $config_table = 'config')
    {
        $this->dbh = $dbh;
        
        if (func_num_args() > 1)
            $this->phpauth_config_table = $config_table;

        $this->config = array();

        $query = $this->dbh->prepare("SELECT * FROM {$this->phpauth_config_table}");
        $query->execute();

        while($row = $query->fetch()) {
            $this->config[$row['setting']] = $row['value'];
        }
    }

    /**
     * Return config value
     * @param $setting  -- key
     * @return mixed    -- config value
     */
    public function __get($setting)
    {
        return $this->config[$setting];
    }

    /**
     * Set config value
     * @param $setting  -- key
     * @param $value    -- config value
     * @return bool     -- true if no any errors occured
     */
    public function __set($setting, $value)
    {
        $query = $this->dbh->prepare("UPDATE {$this->phpauth_config_table} SET value = ? WHERE setting = ?");

        if($query->execute(array($value, $setting))) {
            $this->config[$setting] = $value;
            return true;
        } else {
            return false;
        }
    }
}

?><commit_msg>update config class, need to keep it simple and clean<commit_after><?php
class Config
{
    private $dbh;
    private $config;

    /**
     * Config::__construct()
     * 
     * @param mixed $dbh
     * @param string $config_table
     * @return
     */
    public function __construct(\PDO $dbh, $config_table = 'config')
    {
        $this->dbh = $dbh;
        $this->phpauth_config_table = $config_table;
        
        $this->config = array();

        $query = $this->dbh->query("SELECT * FROM {$this->phpauth_config_table}");

        while($row = $query->fetch()) {
            $this->config[$row['setting']] = $row['value'];
        }
    }

    /**
     * Config::__get()
     * 
     * @param mixed $setting
     * @return
     */
    public function __get($setting)
    {
        return $this->config[$setting];
    }

    /**
     * Config::__set()
     * 
     * @param mixed $setting
     * @param mixed $value
     * @return
     */
    public function __set($setting, $value)
    {
        $query = $this->dbh->prepare("UPDATE {$this->phpauth_config_table} SET value = ? WHERE setting = ?");

        if($query->execute(array($value, $setting))) {
            $this->config[$setting] = $value;
            return true;
        } 
        return false;
    }
}
{'fraction_non_alphanumeric': 0.1505341534477177, 'fraction_numerical': 0.0003237293622531564, 'mean_word_length': 2.0264446620959844, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 34, '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': '1305107', 'n_tokens_mistral': 940, 'n_tokens_neox': 922, 'n_words': 221}