<commit_before><?php

namespace Parable\ORM;

class Query
{
    /** Join types */
    const JOIN_INNER = 1;
    const JOIN_LEFT  = 2;
    const JOIN_RIGHT = 3;
    const JOIN_FULL  = 4;

    /** Order by types */
    const ORDER_ASC  = 'ASC';
    const ORDER_DESC = 'DESC';

    /** @var \Parable\ORM\Query\Condition[] */
    protected $where = [];

    /** @var \Parable\ORM\Query\Condition[] */
    protected $having = [];

    /** @var array */
    protected $values = [];

    /** @var array */
    protected $orderBy = [];

    /** @var array */
    protected $groupBy = [];

    /** @var array */
    protected $select = ['*'];

    /** @var string */
    protected $action = 'select';

    /** @var \Parable\ORM\Query\Condition[][] */
    protected $joins = [
        self::JOIN_INNER => [],
        self::JOIN_LEFT  => [],
        self::JOIN_RIGHT => [],
        self::JOIN_FULL  => [],
    ];

    /** @var null|int */
    protected $limitOffset = [];

    /** @var null|string */
    protected $tableName;

    /** @var \Parable\ORM\Database */
    protected $database;

    /** @var array */
    protected $acceptedValues = ['select', 'insert', 'update', 'delete'];

    /** @var array */
    protected $nonQuoteStrings = ['*', 'sum', 'max', 'min', 'count', 'avg'];

    public function __construct(
        \Parable\ORM\Database $database
    ) {
        $this->database = $database;
    }

    /**
     * Set the tableName to work with.
     *
     * @param string $tableName
     *
     * @return $this
     */
    public function setTableName($tableName)
    {
        $this->tableName = $tableName;
        return $this;
    }

    /**
     * Return the currently set tableName.
     *
     * @return string
     */
    public function getTableName()
    {
        return $this->tableName;
    }

    /**
     * Return the currently set tableName, quoted.
     *
     * @return null|string
     */
    public function getQuotedTableName()
    {
        return $this->quoteIdentifier($this->tableName);
    }

    /**
     * Set the type of query we're going to do.
     *
     * @param string $action
     *
     * @return $this
     * @throws \Parable\ORM\Exception
     */
    public function setAction($action)
    {
        if (!in_array($action, $this->acceptedValues)) {
            $acceptedValuesString = implode(', ', $this->acceptedValues);
            throw new \Parable\ORM\Exception("Invalid action set, only {$acceptedValuesString} are allowed.");
        }
        $this->action = $action;
        return $this;
    }

    /**
     * Return the action.
     *
     * @return string
     */
    public function getAction()
    {
        return $this->action;
    }

    /**
     * In case of a select, what we're going to select (default *).
     *
     * @param array $select
     *
     * @return $this
     */
    public function select(array $select)
    {
        $this->select = $select;
        return $this;
    }

    /**
     * Add a where condition set.
     *
     * @param \Parable\ORM\Query\ConditionSet $set
     *
     * @return $this
     */
    public function where(\Parable\ORM\Query\ConditionSet $set)
    {
        $this->where[] = $set;
        return $this;
    }

    /**
     * Add an array of where condition sets.
     *
     * @param \Parable\ORM\Query\ConditionSet[] $sets
     *
     * @return $this
     */
    public function whereMany(array $sets)
    {
        foreach ($sets as $set) {
            $this->where($set);
        }
        return $this;
    }

    /**
     * Add a condition based on key/comparator/value.
     *
     * @param string      $key
     * @param string      $comparator
     * @param string|null $value
     *
     * @return $this
     */
    public function whereCondition($key, $comparator, $value = null, $tableName = null)
    {
        $this->where($this->buildAndSet([
            [$key, $comparator, $value, $tableName]
        ]));
        return $this;
    }

    /**
     * Add a having condition set.
     *
     * @param \Parable\ORM\Query\ConditionSet $set
     *
     * @return $this
     */
    public function having(\Parable\ORM\Query\ConditionSet $set)
    {
        $this->having[] = $set;<commit_msg>Fix comment<commit_after><?php

namespace Parable\ORM;

class Query
{
    /** Join types */
    const JOIN_INNER = 1;
    const JOIN_LEFT  = 2;
    const JOIN_RIGHT = 3;
    const JOIN_FULL  = 4;

    /** Order by types */
    const ORDER_ASC  = 'ASC';
    const ORDER_DESC = 'DESC';

    /** @var \Parable\ORM\Query\Condition[] */
    protected $where = [];

    /** @var \Parable\ORM\Query\Condition[] */
    protected $having = [];

    /** @var array */
    protected $values = [];

    /** @var array */
    protected $orderBy = [];

    /** @var array */
    protected $groupBy = [];

    /** @var array */
    protected $select = ['*'];

    /** @var string */
    protected $action = 'select';

    /** @var \Parable\ORM\Query\Condition[][] */
    protected $joins = [
        self::JOIN_INNER => [],
        self::JOIN_LEFT  => [],
        self::JOIN_RIGHT => [],
        self::JOIN_FULL  => [],
    ];

    /** @var null|int */
    protected $limitOffset = [];

    /** @var null|string */
    protected $tableName;

    /** @var \Parable\ORM\Database */
    protected $database;

    /** @var array */
    protected $acceptedValues = ['select', 'insert', 'update', 'delete'];

    /** @var array */
    protected $nonQuoteStrings = ['*', 'sum', 'max', 'min', 'count', 'avg'];

    public function __construct(
        \Parable\ORM\Database $database
    ) {
        $this->database = $database;
    }

    /**
     * Set the tableName to work with.
     *
     * @param string $tableName
     *
     * @return $this
     */
    public function setTableName($tableName)
    {
        $this->tableName = $tableName;
        return $this;
    }

    /**
     * Return the currently set tableName.
     *
     * @return string
     */
    public function getTableName()
    {
        return $this->tableName;
    }

    /**
     * Return the currently set tableName, quoted.
     *
     * @return null|string
     */
    public function getQuotedTableName()
    {
        return $this->quoteIdentifier($this->tableName);
    }

    /**
     * Set the type of query we're going to do.
     *
     * @param string $action
     *
     * @return $this
     * @throws \Parable\ORM\Exception
     */
    public function setAction($action)
    {
        if (!in_array($action, $this->acceptedValues)) {
            $acceptedValuesString = implode(', ', $this->acceptedValues);
            throw new \Parable\ORM\Exception("Invalid action set, only {$acceptedValuesString} are allowed.");
        }
        $this->action = $action;
        return $this;
    }

    /**
     * Return the action.
     *
     * @return string
     */
    public function getAction()
    {
        return $this->action;
    }

    /**
     * In case of a select, what we're going to select (default *).
     *
     * @param array $select
     *
     * @return $this
     */
    public function select(array $select)
    {
        $this->select = $select;
        return $this;
    }

    /**
     * Add a where condition set.
     *
     * @param \Parable\ORM\Query\ConditionSet $set
     *
     * @return $this
     */
    public function where(\Parable\ORM\Query\ConditionSet $set)
    {
        $this->where[] = $set;
        return $this;
    }

    /**
     * Add an array of where condition sets.
     *
     * @param \Parable\ORM\Query\ConditionSet[] $sets
     *
     * @return $this
     */
    public function whereMany(array $sets)
    {
        foreach ($sets as $set) {
            $this->where($set);
        }
        return $this;
    }

    /**
     * Add a condition based on key/comparator/value, with an optional $tableName.
     *
     * @param string      $key
     * @param string      $comparator
     * @param string|null $value
     * @param string|null $tableName
     *
     * @return $this
     */
    public function whereCondition($key, $comparator, $value = null, $tableName = null)
    {
        $this->where($this->buildAndSet([
            [$key, $comparator, $value, $tableName]
        ]));
        return $this;
    }

    /**
     * Add a having condition set.
     *
     * @param \Parable\ORM\Query\ConditionSet $set
     *
     * @return $this
     */
    public function having(\Parable\ORM\Query\ConditionSet $set)
    {
        $this->having[] = $set;
{'fraction_non_alphanumeric': 0.1510723544661796, 'fraction_numerical': 0.0009427292010370022, 'mean_word_length': 1.8356164383561644, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 41, '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': '7512124', 'n_tokens_mistral': 2656, 'n_tokens_neox': 2580, 'n_words': 617}