<commit_before><?php
/**
 * Query Builder Build Sql Elements
 *
 * @package    Molajo
 * @copyright  2014 <NAME>. All rights reserved.
 * @license    http://www.opensource.org/licenses/mit-license.html MIT License
 */
namespace Molajo\Query\Builder;

/**
 * Query Builder Build Sql Elements
 *
 * Sql - BuildSql - BuildSqlElements - BuildSqlGroups - SetData - EditData - FilterData - Base
 *
 * Processes output data, already filtered will be escaped in getLoop
 *
 * @package  Molajo
 * @license  http://www.opensource.org/licenses/mit-license.html MIT License
 * @since    1.0
 */
abstract class BuildSqlElements extends BuildSqlGroups
{
    /**
     * Generate Element SQL
     *
     * @param   string $type
     *
     * @return  string
     * @since   1.0
     */
    protected function getElement($type)
    {
        if ($this->useGetElement($type) === false) {
            return '';
        }

        if ($type === 'limit') {
            return $this->getElementLimit();
        }

        return $this->getElementStandard($type);
    }

    /**
     * Get Standard Element
     *
     * @param   $type
     *
     * @return  string
     * @since   1.0
     */
    protected function getElementStandard($type)
    {
        $a = $this->groups_array[$type];

        if ($type === 'where' || $type === 'having') {
            $output = $this->getGroups($this->{$type . '_group'}, $this->$type, $a['connector']);
        } else {
            $array  = $this->getElementsArray($type, $a['get_value'], $a['get_column'], $a['use_alias']);
            $output = $this->getLoop($array, $a['key_value']);
        }

        return $this->returnGetElement($a['return_literal'], $output);
    }

    /**
     * Does SQL for this element need to be built?
     *
     * @param   string $type
     *
     * @return  boolean
     * @since   1.0
     */
    protected function useGetElement($type)
    {
        if (count($this->$type) === 0) {
            return false;
        }

        return true;
    }

    /**
     * Generate SQL for Limit
     *
     * @return  string
     * @since   1.0
     */
    protected function getElementLimit()
    {
        if ((int)$this->offset === 0 && (int)$this->limit === 0) {
        } else {
            return 'LIMIT ' . $this->offset . ', ' . $this->limit;
        }

        return '';
    }

    /**
     * Return getElement Value
     *
     * @param   string $return_literal
     * @param   string $output
     *
     * @return  string
     * @since   1.0
     */
    protected function returnGetElement($return_literal, $output = '')
    {
        if (trim($output) === '') {
            return '';
        }

        return trim($return_literal . ' ' . $output);
    }

    /**
     * Generate array of column names, values, or name-value pairs
     *
     * @param   string  $type
     * @param   boolean $get_value
     * @param   boolean $get_column
     * @param   boolean $use_alias
     *
     * @return  string
     * @since   1.0
     */
    protected function getElementsArray($type, $get_value = true, $get_column = true, $use_alias = true)
    {
        $array = array();

        if ($type === 'columns') {
            $this->setColumnPrefix();
        }

        foreach ($this->$type as $item) {
            $array = $this->getElementsArrayItem($item, $get_value, $get_column, $use_alias, $array);
        }

        return $array;
    }

    /**
     * Generate array of column names, values, or name-value pairs
     *
     * @param   string  $type
     * @param   boolean $get_value
     * @param   boolean $get_column
     * @param   boolean $use_alias
     * @param   array   $array
     *
     * @return  string
     * @since   1.0
     */
    protected function getElementsArrayItem($item, $get_value = true, $get_column = true, $use_alias = true, $array)
    {<commit_msg>Defaults<commit_after><?php
/**
 * Query Builder Build Sql Elements
 *
 * @package    Molajo
 * @copyright  2014 <NAME>. All rights reserved.
 * @license    http://www.opensource.org/licenses/mit-license.html MIT License
 */
namespace Molajo\Query\Builder;

/**
 * Query Builder Build Sql Elements
 *
 * Sql - BuildSql - BuildSqlElements - BuildSqlGroups - SetData - EditData - FilterData - Base
 *
 * Processes output data, already filtered will be escaped in getLoop
 *
 * @package  Molajo
 * @license  http://www.opensource.org/licenses/mit-license.html MIT License
 * @since    1.0
 */
abstract class BuildSqlElements extends BuildSqlGroups
{
    /**
     * Generate Element SQL
     *
     * @param   string $type
     *
     * @return  string
     * @since   1.0
     */
    protected function getElement($type)
    {
        if ($this->useGetElement($type) === false) {
            return '';
        }

        if ($type === 'limit') {
            return $this->getElementLimit();
        }

        return $this->getElementStandard($type);
    }

    /**
     * Get Standard Element
     *
     * @param   $type
     *
     * @return  string
     * @since   1.0
     */
    protected function getElementStandard($type)
    {
        $a = $this->groups_array[$type];

        if ($type === 'where' || $type === 'having') {
            $output = $this->getGroups($this->{$type . '_group'}, $this->$type, $a['connector']);
        } else {
            $array  = $this->getElementsArray($type, $a['get_value'], $a['get_column'], $a['use_alias']);
            $output = $this->getLoop($array, $a['key_value']);
        }

        return $this->returnGetElement($a['return_literal'], $output);
    }

    /**
     * Does SQL for this element need to be built?
     *
     * @param   string $type
     *
     * @return  boolean
     * @since   1.0
     */
    protected function useGetElement($type)
    {
        if (count($this->$type) === 0) {
            return false;
        }

        return true;
    }

    /**
     * Generate SQL for Limit
     *
     * @return  string
     * @since   1.0
     */
    protected function getElementLimit()
    {
        if ((int)$this->offset === 0 && (int)$this->limit === 0) {
        } else {
            return 'LIMIT ' . $this->offset . ', ' . $this->limit;
        }

        return '';
    }

    /**
     * Return getElement Value
     *
     * @param   string $return_literal
     * @param   string $output
     *
     * @return  string
     * @since   1.0
     */
    protected function returnGetElement($return_literal, $output = '')
    {
        if (trim($output) === '') {
            return '';
        }

        return trim($return_literal . ' ' . $output);
    }

    /**
     * Generate array of column names, values, or name-value pairs
     *
     * @param   string  $type
     * @param   boolean $get_value
     * @param   boolean $get_column
     * @param   boolean $use_alias
     *
     * @return  string
     * @since   1.0
     */
    protected function getElementsArray($type, $get_value = true, $get_column = true, $use_alias = true)
    {
        $array = array();

        if ($type === 'columns') {
            $this->setColumnPrefix();
        }

        foreach ($this->$type as $item) {
            $array = $this->getElementsArrayItem($item, $get_value, $get_column, $use_alias, $array);
        }

        return $array;
    }

    /**
     * Generate array of column names, values, or name-value pairs
     *
     * @param   string  $type
     * @param   boolean $get_value
     * @param   boolean $get_column
     * @param   boolean $use_alias
     * @param   array   $array
     *
     * @return  string
     * @since   1.0
     */
    protected function getElementsArrayItem($item, $get_value, $get_column, $use_alias, $array)
    {
{'fraction_non_alphanumeric': 0.142652049073349, 'fraction_numerical': 0.006003654398329418, 'mean_word_length': 1.8949754438987534, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '3727767', 'n_tokens_mistral': 2338, 'n_tokens_neox': 2292, 'n_words': 551}