<commit_before><?php
namespace Tuum\Form\Tags;

/**
 * Class Select
 *
 * @package Tuum\Form\Tags
 *
 * @method $this value(string $value)
 * @method $this required()
 * @method $this onclick(string $class)
 */
class Select extends Tag
{
    use ElementTrait;

    /**
     * @var array
     */
    protected $list = array();

    /**
     * @param string $name
     * @param array  $list
     * @param null   $value
     */
    public function __construct($name, $list, $value = null)
    {
        parent::__construct('select');
        $this->list = $list;
        $this->setAttribute('name', $name);
        $this->setAttribute('value', (array) $value);
    }

    /**
     * @return string
     */
    public function toString()
    {
        return $this->formSelect();
    }

    /**
     * @return string
     */
    private function formSelect()
    {
        $selectedValue = (array) $this->get('value');
        $this->setAttribute('value', false);
        $html = '';
        foreach ($this->list as $value => $label) {
            if (in_array((string)$value, $selectedValue)) {
                $html .= "\n  <option value=\"{$value}\" selected>{$label}</option>";
            } else {
                $html .= "\n  <option value=\"{$value}\">{$label}</option>";
            }
        }
        if ($html) {
            $this->contents($html . "\n");
            $html = (string)$this->convertToString($this);<commit_msg>add so called head in select list.<commit_after><?php
namespace Tuum\Form\Tags;

/**
 * Class Select
 *
 * @package Tuum\Form\Tags
 *
 * @method $this value(string $value)
 * @method $this required()
 * @method $this onclick(string $class)
 */
class Select extends Tag
{
    use ElementTrait;

    /**
     * @var array
     */
    private $list = array();

    /**
     * @var string
     */
    private $head;

    /**
     * @param string $name
     * @param array  $list
     * @param null   $value
     */
    public function __construct($name, $list, $value = null)
    {
        parent::__construct('select');
        $this->list = $list;
        $this->setAttribute('name', $name);
        $this->setAttribute('value', (array) $value);
    }

    /**
     * add an empty selection at the beginning of the list, 
     * such as 'select an item...'. 
     * 
     * @param string $head
     * @return $this
     */
    public function head($head)
    {
        $this->head = $head;
        return $this;
    }
    /**
     * @return string
     */
    public function toString()
    {
        return $this->formSelect();
    }

    /**
     * @return string
     */
    private function formSelect()
    {
        $selectedValue = (array) $this->get('value');
        $this->setAttribute('value', false);
        $html = '';
        if ($this->head) {
            $html .= "\n  <option value=\"\" selected>{$this->head}</option>";
        }
        foreach ($this->list as $value => $label) {
            if (in_array((string)$value, $selectedValue)) {
                $html .= "\n  <option value=\"{$value}\" selected>{$label}</option>";
            } else {
                $html .= "\n  <option value=\"{$value}\">{$label}</option>";
            }
        }
        if ($html) {
            $this->contents($html . "\n");
            $html = (string)$this->convertToString($this);
{'fraction_non_alphanumeric': 0.17785133915136925, 'fraction_numerical': 0.0, 'mean_word_length': 1.8929503916449086, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 36, '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': '4850680', 'n_tokens_mistral': 988, 'n_tokens_neox': 981, 'n_words': 231}