<commit_before><?php

class Hoff
{
    private $types = [];
    
    private $indexTypes = [];
    
    private $db = null;
    
    public $columns = [];
    public $table = [];
    public $primarys = [];
    
    public $lastQuery = '';
    
    function __construct($db)
    {
        $this->db = $db;
        
        $this->clean();
    }
    
    function clean()
    {
        $this->columns = [];
        $this->table   = ['name'        => null,
                          'type'        => 'INNODB',
                          'uniqueKeys'  => [],
                          'primaryKeys' => [],
                          'indexKeys'   => [],
                          'comment'     => null];
    }
    
    function setTableType($type)
    {
        $this->table['type'] = $type;
    }
 
    
    function _create($tableName, $comment = null)
    {
        if($comment)
            $this->table['comment'] = $comment;
        
        $this->db->rawQuery($this->tableBuilder());
        $this->clean();
        
        return $this;
    }
    
    function _column($columnName)
    {
        $this->columns[] = ['name'          => $columnName,
                            'type'          => null,
                            'length'        => null,
                            'comment'       => null,
                            'unsigned'      => false,
                            'primary'       => null,
                            'unique'        => null,
                            'index'         => null,
                            'autoIncrement' => false,
                            'default'       => false,
                            'nullable'      => false,
                            'extras'        => []];
        return $this;
    }

    function __call($method, $args)
    {
        switch($method)
        {
            /** One length required */
            case 'tinyint'   :
            case 'smallint'  :
            case 'mediumint' :
            case 'int'       :
            case 'bigint'    :
            case 'char'      :
            case 'varchar'   :
            case 'binary'    :
            case 'varbinary' :
            case 'bit'       :
                /** bit(1) */
                return $this->setType($method, $args[0]);
                break;
            
            /** No length needed */
            case 'tinytext'  :
            case 'text'      :
            case 'mediumtext':
            case 'longtext'  :
            case 'tinyblob'  :
            case 'blob'      :
            case 'mediumblob':
            case 'longblob'  :
            case 'date'      :
            case 'datetime'  :
            case 'time'      :
            case 'timestamp' :
            case 'year'      :
                /** year() */
                return $this->setType($method);
                break;
            
            /** Two lengths required */
            case 'double' :
            case 'decimal':
                /** double([0, 2]) */
                return $this->setType($method, $args[0]);
                break;
            
            /** One or two lengths required */
            case 'float':
                /** float([0, 2]) or float([1]) or float(1) */
                return $this->setType($method, $args[0]);
                break;
            
            /** Options length */
            case 'enum':
            case 'set' :
                /** enum(['A', 'B', 'C']) */
                return $this->setType($method, $args[0]);
                break; 
            
            case 'InnoDB':
            case 'MyISAM':
                return $this->setTableType($method);
                break;
            
            case 'primary' :
            case 'unique'  :
            case 'index'   :
                $groupName = isset($args[0]) ? $args[0] : null;
                $columns   = isset($args[1]) ? $args[1] : null;
                $this->setIndex($method, $groupName, $columns);
                break;
                
            case 'nullable':
            case 'comment' :
            case 'unsigned':
                return call_user_func_array([$this, '_' . $method], $args);
                break;
            
            /** Default functions */
            default:
                return call_user_func_array([$this, $method], $args);
        }
    }
 
    function setType($type, $length = null, $extras = null)
    {
        end($this->columns);
        $lastColumn = &$this->columns[key($this->columns)];
        
        $lastColumn['type']   = $type;
        $lastColumn['length'] = $length;
        $lastColumn['extras'] = $extras;
        
        return $this;
    }
    
    
    
    
    /***********************************************<commit_msg>Trying to fix the loop, the default function is now with the _ symbol<commit_after><?php

class Hoff
{
    private $types = [];
    
    private $indexTypes = [];
    
    private $db = null;
    
    public $columns = [];
    public $table = [];
    public $primarys = [];
    
    public $lastQuery = '';
    
    function __construct($db)
    {
        $this->db = $db;
        
        $this->clean();
    }
    
    function clean()
    {
        $this->columns = [];
        $this->table   = ['name'        => null,
                          'type'        => 'INNODB',
                          'uniqueKeys'  => [],
                          'primaryKeys' => [],
                          'indexKeys'   => [],
                          'comment'     => null];
    }
    
    function setTableType($type)
    {
        $this->table['type'] = $type;
    }
 
    
    function _create($tableName, $comment = null)
    {
        if($comment)
            $this->table['comment'] = $comment;
        
        $this->db->rawQuery($this->tableBuilder());
        $this->clean();
        
        return $this;
    }
    
    function _column($columnName)
    {
        $this->columns[] = ['name'          => $columnName,
                            'type'          => null,
                            'length'        => null,
                            'comment'       => null,
                            'unsigned'      => false,
                            'primary'       => null,
                            'unique'        => null,
                            'index'         => null,
                            'autoIncrement' => false,
                            'default'       => false,
                            'nullable'      => false,
                            'extras'        => []];
        return $this;
    }

    function __call($method, $args)
    {
        switch($method)
        {
            /** One length required */
            case 'tinyint'   :
            case 'smallint'  :
            case 'mediumint' :
            case 'int'       :
            case 'bigint'    :
            case 'char'      :
            case 'varchar'   :
            case 'binary'    :
            case 'varbinary' :
            case 'bit'       :
                /** bit(1) */
                return $this->setType($method, $args[0]);
                break;
            
            /** No length needed */
            case 'tinytext'  :
            case 'text'      :
            case 'mediumtext':
            case 'longtext'  :
            case 'tinyblob'  :
            case 'blob'      :
            case 'mediumblob':
            case 'longblob'  :
            case 'date'      :
            case 'datetime'  :
            case 'time'      :
            case 'timestamp' :
            case 'year'      :
                /** year() */
                return $this->setType($method);
                break;
            
            /** Two lengths required */
            case 'double' :
            case 'decimal':
                /** double([0, 2]) */
                return $this->setType($method, $args[0]);
                break;
            
            /** One or two lengths required */
            case 'float':
                /** float([0, 2]) or float([1]) or float(1) */
                return $this->setType($method, $args[0]);
                break;
            
            /** Options length */
            case 'enum':
            case 'set' :
                /** enum(['A', 'B', 'C']) */
                return $this->setType($method, $args[0]);
                break; 
            
            case 'InnoDB':
            case 'MyISAM':
                return $this->setTableType($method);
                break;
            
            case 'primary' :
            case 'unique'  :
            case 'index'   :
                $groupName = isset($args[0]) ? $args[0] : null;
                $columns   = isset($args[1]) ? $args[1] : null;
                return $this->setIndex($method, $groupName, $columns);
                break;
                
            //case 'nullable':
            //case 'comment' :
            //case 'unsigned':
            //    return call_user_func_array([$this, '_' . $method], $args);
            //    break;
            
            /** Default functions */
            default:
                return call_user_func_array([$this, '_' . $method], $args);
                break;
        }
    }
 
    function setType($type, $length = null, $extras = null)
    {
        end($this->columns);
        $lastColumn = &$this->columns[key($this->columns)];
        
        $lastColumn['type']   = $type;
        $lastColumn['length'] = $length;
        $lastColumn['extras'] = $extras;
        
        return $this;
    }
    
    
    
    
    /***********************************************
{'fraction_non_alphanumeric': 0.1438512671375156, 'fraction_numerical': 0.0031159119235562942, 'mean_word_length': 0.963899653273506, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 81, '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': '3162357', 'n_tokens_mistral': 2536, 'n_tokens_neox': 2482, 'n_words': 508}