<commit_before><?php
namespace vakata\database\schema;

/**
 * A column definition
 */
class TableColumn
{
    protected $name;
    protected $type;
    protected $btype = 'text';
    protected $values = [];
    protected $default = null;
    protected $comment = null;
    protected $nullable = false;
    protected $length = null;

    public function __construct(string $name)
    {
        $this->setName($name);
    }

    public static function fromArray(string $name, array $data = [])
    {
        $instance = new self($name);
        if (isset($data['Type'])) {
            $instance->setType($data['Type']);
        }
        if (isset($data['type'])) {
            $instance->setType($data['type']);
        }
        if (isset($data['Comment'])) {
            $instance->setComment($data['Comment']);
        }
        if (isset($data['comment'])) {
            $instance->setComment($data['comment']);
        }
        if (isset($data['Null']) && $data['Null'] === 'YES') {
            $instance->setNullable(true);
        }
        if (isset($data['nullable']) && is_bool($data['nullable'])) {
            $instance->setNullable($data['nullable']);
        }
        if (isset($data['Default'])) {
            $instance->setDefault($data['Default']);
        }
        if (isset($data['default'])) {
            $instance->setDefault($data['default']);
        }
        if (isset($data['length'])) {
            $instance->setLength($data['length']);
        }
        if ($instance->getBasicType() === 'enum' && strpos($instance->getType(), 'enum(') === 0) {
            $temp = array_map(function ($v) {
                return str_replace("''", "'", $v);
            }, explode("','", substr($instance->getType(), 6, -2)));
            $instance->setValues($temp);
        }
        if (isset($data['values']) && is_array($data['values'])) {
            $instance->setValues($data['values']);
        }
        if (isset($data['DATA_TYPE'])) {
            $instance->setType($data['DATA_TYPE']);
        }
        if (isset($data['NULLABLE']) && $data['NULLABLE'] !== 'N') {
            $instance->setNullable(true);
        }
        if (isset($data['DATA_DEFAULT'])) {
            $instance->setDefault($data['DATA_DEFAULT']);
        }
        return $instance;
    }

    public function getName()
    {
        return $this->name;
    }
    public function getType()
    {
        return $this->type;
    }
    public function getValues()
    {
        return $this->values;
    }
    public function getDefault()
    {
        return $this->default;
    }
    public function isNullable()
    {
        return $this->nullable;
    }
    public function getComment()<commit_msg>improved postgre support<commit_after><?php
namespace vakata\database\schema;

/**
 * A column definition
 */
class TableColumn
{
    protected $name;
    protected $type;
    protected $btype = 'text';
    protected $values = [];
    protected $default = null;
    protected $comment = null;
    protected $nullable = false;
    protected $length = null;

    public function __construct(string $name)
    {
        $this->setName($name);
    }

    public static function fromArray(string $name, array $data = [])
    {
        $instance = new self($name);
        if (isset($data['Type'])) {
            $instance->setType($data['Type']);
        }
        if (isset($data['type'])) {
            $instance->setType($data['type']);
        }
        if (isset($data['Comment'])) {
            $instance->setComment($data['Comment']);
        }
        if (isset($data['comment'])) {
            $instance->setComment($data['comment']);
        }
        if (isset($data['Null']) && $data['Null'] === 'YES') {
            $instance->setNullable(true);
        }
        if (isset($data['nullable']) && is_bool($data['nullable'])) {
            $instance->setNullable($data['nullable']);
        }
        if (isset($data['Default'])) {
            $instance->setDefault($data['Default']);
        }
        if (isset($data['default'])) {
            $instance->setDefault($data['default']);
        }
        if (isset($data['length'])) {
            $instance->setLength($data['length']);
        }
        if ($instance->getBasicType() === 'enum' && strpos($instance->getType(), 'enum(') === 0) {
            $temp = array_map(function ($v) {
                return str_replace("''", "'", $v);
            }, explode("','", substr($instance->getType(), 6, -2)));
            $instance->setValues($temp);
        }
        if (isset($data['values']) && is_array($data['values'])) {
            $instance->setValues($data['values']);
        }
        if (isset($data['DATA_TYPE'])) {
            $instance->setType($data['DATA_TYPE']);
        }
        if (isset($data['NULLABLE']) && $data['NULLABLE'] !== 'N') {
            $instance->setNullable(true);
        }
        if (isset($data['DATA_DEFAULT'])) {
            $instance->setDefault($data['DATA_DEFAULT']);
        }
        if (isset($data['data_type'])) {
            $instance->setType($data['data_type']);
        }
        if (isset($data['column_default'])) {
            $instance->setDefault(trim("'", explode('::', $data['DATA_DEFAULT'])[0]));
        }
        if (isset($data['is_nullable']) && $data['is_nullable'] == 'YES') {
            $instance->setNullable(true);
            if (!isset($data['column_default'])) {
                $instance->setDefault(null);
            }
        }
        return $instance;
    }

    public function getName()
    {
        return $this->name;
    }
    public function getType()
    {
        return $this->type;
    }
    public function getValues()
    {
        return $this->values;
    }
    public function getDefault()
    {
        return $this->default;
    }
    public function isNullable()
    {
        return $this->nullable;
    }
    public function getComment()
{'fraction_non_alphanumeric': 0.19064565327910524, 'fraction_numerical': 0.0011862396204033216, 'mean_word_length': 2.1646112600536194, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 53, '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': '3681862', 'n_tokens_mistral': 1649, 'n_tokens_neox': 1650, 'n_words': 289}