<commit_before><?php

namespace Manavo\BootstrapForms;

use Illuminate\Html\FormBuilder as IlluminateFormBuilder;

class FormBuilder extends IlluminateFormBuilder {

	/**
	 * An array containing the currently opened form groups.
	 *
	 * @var array
	 */
	protected $groupStack = array();

	/**
	 * Open a new form group.
	 *
	 * @param  string  $name
	 * @param  mixed   $label
	 * @param  array   $options
	 * @param  array   $labelOptions
	 * @return string
	 */
	public function openGroup($name, $label = null, $options = array(), $labelOptions = array())
	{
		$options = $this->appendClassToOptions('form-group', $options);

		// Append the name of the group to the groupStack.
		$this->groupStack[] = $name;

		if ($this->hasErrors($name))
		{
			// If the form element with the given name has any errors,
			// apply the 'has-error' class to the group.
			$options = $this->appendClassToOptions('has-error', $options);
		}

		// If a label is given, we set it up here. Otherwise, we will just
		// set it to an empty string.
		$label = $label ? $this->label($name, $label, $labelOptions) : '';

		return '<div'.$this->html->attributes($options).'>'.$label;
	}

	/**
	 * Close out the last opened form group.
	 *
	 * @return string
	 */
	public function closeGroup()
	{
		// Get the last added name from the groupStack and
		// remove it from the array.
		$name = array_pop($this->groupStack);

		// Get the formatted errors for this form group.
		$errors = $this->getFormattedErrors($name);

		// Append the errors to the group and close it out.
		return $errors.'</div>';
	}

	/**
	 * Create a form input field.
	 *
	 * @param  string  $type
	 * @param  string  $name
	 * @param  string  $value
	 * @param  array   $options
	 * @return string
	 */
	public function input($type, $name, $value = null, $options = array())
	{
		// Don't add form-control for some input types (like submit, checkbox, radio)
		if (!in_array($type, ['submit', 'checkbox', 'radio'])) {
			$options = $this->appendClassToOptions('form-control', $options);
		}

		// Call the parent input method so that Laravel can handle
		// the rest of the input set up.
		return parent::input($type, $name, $value, $options);
	}

	/**
	 * Create a select box field.
	 *
	 * @param  string  $name
	 * @param  array   $list
	 * @param  string  $selected
	 * @param  array   $options
	 * @return string
	 */
	public function select($name, $list = array(), $selected = null, $options = array())
	{
		$options = $this->appendClassToOptions('form-control', $options);

		// Call the parent select method so that Laravel can handle
		// the rest of the select set up.
		return parent::select($name, $list, $selected, $options);
	}

	/**
	 * Create a plain form input field.
	 *
	 * @param  string  $type
	 * @param  string  $name<commit_msg>Don't add form-control class to reset button<commit_after><?php

namespace Manavo\BootstrapForms;

use Illuminate\Html\FormBuilder as IlluminateFormBuilder;

class FormBuilder extends IlluminateFormBuilder {

	/**
	 * An array containing the currently opened form groups.
	 *
	 * @var array
	 */
	protected $groupStack = array();

	/**
	 * Open a new form group.
	 *
	 * @param  string  $name
	 * @param  mixed   $label
	 * @param  array   $options
	 * @param  array   $labelOptions
	 * @return string
	 */
	public function openGroup($name, $label = null, $options = array(), $labelOptions = array())
	{
		$options = $this->appendClassToOptions('form-group', $options);

		// Append the name of the group to the groupStack.
		$this->groupStack[] = $name;

		if ($this->hasErrors($name))
		{
			// If the form element with the given name has any errors,
			// apply the 'has-error' class to the group.
			$options = $this->appendClassToOptions('has-error', $options);
		}

		// If a label is given, we set it up here. Otherwise, we will just
		// set it to an empty string.
		$label = $label ? $this->label($name, $label, $labelOptions) : '';

		return '<div'.$this->html->attributes($options).'>'.$label;
	}

	/**
	 * Close out the last opened form group.
	 *
	 * @return string
	 */
	public function closeGroup()
	{
		// Get the last added name from the groupStack and
		// remove it from the array.
		$name = array_pop($this->groupStack);

		// Get the formatted errors for this form group.
		$errors = $this->getFormattedErrors($name);

		// Append the errors to the group and close it out.
		return $errors.'</div>';
	}

	/**
	 * Create a form input field.
	 *
	 * @param  string  $type
	 * @param  string  $name
	 * @param  string  $value
	 * @param  array   $options
	 * @return string
	 */
	public function input($type, $name, $value = null, $options = array())
	{
		// Don't add form-control for some input types (like submit, checkbox, radio)
		if (!in_array($type, ['submit', 'checkbox', 'radio', 'reset'])) {
			$options = $this->appendClassToOptions('form-control', $options);
		}

		// Call the parent input method so that Laravel can handle
		// the rest of the input set up.
		return parent::input($type, $name, $value, $options);
	}

	/**
	 * Create a select box field.
	 *
	 * @param  string  $name
	 * @param  array   $list
	 * @param  string  $selected
	 * @param  array   $options
	 * @return string
	 */
	public function select($name, $list = array(), $selected = null, $options = array())
	{
		$options = $this->appendClassToOptions('form-control', $options);

		// Call the parent select method so that Laravel can handle
		// the rest of the select set up.
		return parent::select($name, $list, $selected, $options);
	}

	/**
	 * Create a plain form input field.
	 *
	 * @param  string  $type
	 * @param  string  $name
{'fraction_non_alphanumeric': 0.14014883061658398, 'fraction_numerical': 0.0, 'mean_word_length': 3.1599115696389095, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 29, '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': '3388070', 'n_tokens_mistral': 1868, 'n_tokens_neox': 1712, 'n_words': 604}