<commit_before><?php
namespace Core2\Classes\Table\Db;


/**
 * Class Select
 */
class Select {

    /**
     * @var array
     */
    private $sql = [];

    /**
     * @var array
     */
    private $sub_queries = [];


    /**
     * @param string $sql Текст SQL запроса
     */
    public function __construct(string $sql) {
        $this->parse($sql);
    }


    /**
     * Получение колонок
     * @return array
     */
    public function getSelectColumns(): array {

        $columns = [];

        if ( ! empty($this->sql['SELECT'])) {
            $select_explode = explode(',', $this->sql['SELECT']);

            if ( ! empty($select_explode)) {
                foreach ($select_explode as $select_column) {
                    if (preg_match('~\s*(.*)\s+AS\s+[\'"`]?([\w\d_ ]+)[\'"`]?\s*$~mi', trim($select_column), $matches)) {
                        $field = $matches[1];

                        if (preg_match('~^(\[\d*\])$~', $field, $matches_sub_query)) {
                            $field = $this->sub_queries[$matches_sub_query[1]] ?? $field;
                        }

                        $columns[$matches[2]] = $field;

                    } elseif (preg_match('~\s*[\'"`]?([\w\d_ \.]+)[\'"`]?\s*$~mi', trim($select_column), $matches)) {
                        $alise = $matches[1];

                        if (mb_strpos($alise, '.') !== false) {
                            $alise = mb_substr($alise, mb_strrpos($alise, '.') + 1);
                        }

                        $columns[$alise] = $matches[1];
                    }
                }
            }
        }

        return $columns;
    }


    /**
     * @param string|array $where
     */
    public function addWhere($where) {

        $where = is_array($where) ? implode(' AND ', $where) : $where;

        if ( ! empty($this->sql['WHERE'])) {
            $this->sql['WHERE'] .= ' AND ' . $where;
        } else {
            $this->sql['WHERE'] = $where;
        }
    }

<commit_msg>рефакторинг<commit_after><?php
namespace Core2\Classes\Table\Db;


/**
 * Class Select
 */
class Select {

    /**
     * @var array
     */
    private $sql = [];

    /**
     * @var array
     */
    private $sub_queries = [];


    /**
     * @param string $sql Текст SQL запроса
     */
    public function __construct(string $sql) {
        $this->parse($sql);
    }


    /**
     * Получение колонок
     * @return array
     */
    public function getSelectColumns(): array {

        $columns = [];

        if ( ! empty($this->sql['SELECT'])) {
            $select_explode = explode(',', $this->sql['SELECT']);

            if ( ! empty($select_explode)) {
                foreach ($select_explode as $select_column) {
                    if (preg_match('~\s*(.*)\s+AS\s+[\'"`]?([\w\d_ ]+)[\'"`]?\s*$~mi', trim($select_column), $matches)) {
                        $field = $matches[1];

                        if (preg_match('~^(\[\d*\])$~', $field, $matches_sub_query)) {
                            $field = $this->sub_queries[$matches_sub_query[1]] ?? $field;
                        }

                        $columns[$matches[2]] = $field;

                    } elseif (preg_match('~\s*[\'"`]?([\w\d_ \.]+)[\'"`]?\s*$~mi', trim($select_column), $matches)) {
                        $alias = $matches[1];

                        if (mb_strpos($alias, '.') !== false) {
                            $alias = mb_substr($alias, mb_strrpos($alias, '.') + 1);
                        }

                        $columns[$alias] = $matches[1];
                    }
                }
            }
        }

        return $columns;
    }


    /**
     * @param string|array $where
     */
    public function addWhere($where) {

        $where = is_array($where) ? implode(' AND ', $where) : $where;

        if ( ! empty($this->sql['WHERE'])) {
            $this->sql['WHERE'] .= ' AND ' . $where;
        } else {
            $this->sql['WHERE'] = $where;
        }
    }


{'fraction_non_alphanumeric': 0.1927710843373494, 'fraction_numerical': 0.0035140562248995983, 'mean_word_length': 1.410768300060496, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, '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': '3604832', 'n_tokens_mistral': 1283, 'n_tokens_neox': 1219, 'n_words': 200}