<commit_before><?php
namespace Avh\Html;

use Avh\Html\HtmlBuilder;

class FormBuilder
{

    // @var Use tables to create FormBuilder
    private $use_table = false;

    private $option_name;

    private $nonce;

    private $html;

    public function __construct(\Avh\Html\HtmlBuilder $html)
    {
        $this->html = $html;
    }

    /**
     * Generates an opening HTML form tag.
     *
     * // FormBuilder will submit back to the current page using POST
     * echo FormBuilder::open();
     *
     * // FormBuilder will submit to 'search' using GET
     * echo FormBuilder::open('search', array('method' => 'get'));
     *
     * // When "file" inputs are present, you must include the "enctype"
     * echo FormBuilder::open(null, array('enctype' => 'multipart/form-data'));
     *
     * @param mixed $action
     *            form action, defaults to the current request URI, or [Request] class to use
     * @param array $attributes
     *            html attributes
     * @return string
     * @uses HtmlBuilder->attributes
     */
    public function open($action = null, array $attributes = null)
    {
        if (!isset($attributes['method'])) {
            // Use POST method
            $attributes['method'] = 'post';
        }

        return '<form action="' . $action . '"' . $this->html->attributes($attributes) . '>';
    }

    /**
     * Creates the closing form tag.
     *
     * echo FormBuilder::close();
     *
     * @return string
     */
    public function close()
    {
        return '</form>';
    }

    public function openTable(array $attributes = null)
    {
        $this->use_table = true;
        $attributes = array_merge($attributes, array('class' => 'form-table'));
        return '<table ' . $this->html->attributes($attributes) . '>';
    }

    public function closeTable()
    {
        $this->use_table = false;

        return '</table>';
    }

    /**
     * Create the nonce field.
     * Instead of using the standard WordPress function, we duplicate the function but using the methods of this class.
     * This will create a more standard looking HTML output.
     *
     * @param string $nonce
     * @param boolean $referer
     * @return string
     */
    public function fieldNonce($referer = true)
    {
        $nonce_field = $this->hidden('_wpnonce', wp_create_nonce($this->nonce));
        if ($referer) {
            $ref = $_SERVER['REQUEST_URI'];
            $nonce_field .= $this->hidden('_wp_http_referer', $ref);
        }

        return $nonce_field;
    }

    public function fieldSettings($action, $use_nonce = true)
    {
        $return = $this->hidden('action', $action);
        if ($use_nonce) {
            $return .= $this->fieldNonce();
        }

        return $return;
    }

    public function text($label, $name, $value = null, array $attributes = null)
    {
        $text_label = $this->label($name, $label);
        $text_field = $this->input($name, $value, $attributes);

        return $this->output($text_label, $text_field);
    }

    public function checkboxes($label, $name, array $options, array $attributes = null)
    {
        $cb_label = $this->label($name, $label);
        $return = $this->outputLabel($cb_label);
        $cb_field = '';
        foreach ($options as $value => $attr) {
            $cb_checked = (isset($attr['checked']) ? $attr['checked'] : false);
            $cb_field .= $this->checkbox($value, $cb_checked, $attributes);
            $cb_field .= $this->label($value, $attr['text']);
            $cb_field .= '<br>';
        }
        $return .= $this->outputField($cb_field);

        return $return;
    }

    public function select($label, $name, array $options = null, $selected = null, array $attributes = null)
    {
        $select_label = $this->label($name, $label);
        $select_field = $this->getSelect($name, $options, $selected, $attributes);

        return $this->output($select_label, $select_field);
    }

    /**
     * Creates a hidden form input.
     *
     * echo FormBuilder::hidden('csrf', $token);
     *
     * @param string $name
     *            input name
     * @param string $value
     *            input value
     * @param array $attributes
     *            html attributes
     * @return string
     * @uses $this->input
     */<commit_msg>Missing parameter.<commit_after><?php
namespace Avh\Html;

use Avh\Html\HtmlBuilder;

class FormBuilder
{

    // @var Use tables to create FormBuilder
    private $use_table = false;

    private $option_name;

    private $nonce;

    private $html;

    public function __construct(\Avh\Html\HtmlBuilder $html)
    {
        $this->html = $html;
    }

    /**
     * Generates an opening HTML form tag.
     *
     * // FormBuilder will submit back to the current page using POST
     * echo FormBuilder::open();
     *
     * // FormBuilder will submit to 'search' using GET
     * echo FormBuilder::open('search', array('method' => 'get'));
     *
     * // When "file" inputs are present, you must include the "enctype"
     * echo FormBuilder::open(null, array('enctype' => 'multipart/form-data'));
     *
     * @param mixed $action
     *            form action, defaults to the current request URI, or [Request] class to use
     * @param array $attributes
     *            html attributes
     * @return string
     * @uses HtmlBuilder->attributes
     */
    public function open($action = null, array $attributes = null)
    {
        if (!isset($attributes['method'])) {
            // Use POST method
            $attributes['method'] = 'post';
        }

        return '<form action="' . $action . '"' . $this->html->attributes($attributes) . '>';
    }

    /**
     * Creates the closing form tag.
     *
     * echo FormBuilder::close();
     *
     * @return string
     */
    public function close()
    {
        return '</form>';
    }

    public function openTable(array $attributes = null)
    {
        $this->use_table = true;
        $attributes = array_merge($attributes, array('class' => 'form-table'));
        return '<table ' . $this->html->attributes($attributes) . '>';
    }

    public function closeTable()
    {
        $this->use_table = false;

        return '</table>';
    }

    /**
     * Create the nonce field.
     * Instead of using the standard WordPress function, we duplicate the function but using the methods of this class.
     * This will create a more standard looking HTML output.
     *
     * @param string $nonce
     * @param boolean $referer
     * @return string
     */
    public function fieldNonce($referer = true)
    {
        $nonce_field = $this->hidden('_wpnonce', wp_create_nonce($this->nonce));
        if ($referer) {
            $ref = $_SERVER['REQUEST_URI'];
            $nonce_field .= $this->hidden('_wp_http_referer', $ref);
        }

        return $nonce_field;
    }

    public function fieldSettings($action, $use_nonce = true)
    {
        $return = $this->hidden('action', $action);
        if ($use_nonce) {
            $return .= $this->fieldNonce();
        }

        return $return;
    }

    public function text($label, $name, $value = null, array $attributes = null)
    {
        $text_label = $this->label($name, $label);
        $text_field = $this->input($name, $value, $attributes);

        return $this->output($text_label, $text_field);
    }

    public function checkboxes($label, $name, array $options, array $attributes = null)
    {
        $cb_label = $this->label($name, $label);
        $return = $this->outputLabel($cb_label);
        $cb_field = '';
        foreach ($options as $value => $attr) {
            $cb_checked = (isset($attr['checked']) ? $attr['checked'] : false);
            $cb_field .= $this->checkbox($name, $value, $cb_checked, $attributes);
            $cb_field .= $this->label($value, $attr['text']);
            $cb_field .= '<br>';
        }
        $return .= $this->outputField($cb_field);

        return $return;
    }

    public function select($label, $name, array $options = null, $selected = null, array $attributes = null)
    {
        $select_label = $this->label($name, $label);
        $select_field = $this->getSelect($name, $options, $selected, $attributes);

        return $this->output($select_label, $select_field);
    }

    /**
     * Creates a hidden form input.
     *
     * echo FormBuilder::hidden('csrf', $token);
     *
     * @param string $name
     *            input name
     * @param string $value
     *            input value
     * @param array $attributes
     *            html attributes
     * @return string
     * @uses $this->input
     */
{'fraction_non_alphanumeric': 0.14409521608504738, 'fraction_numerical': 0.0, 'mean_word_length': 2.210311572700297, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 71, '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': '640500', 'n_tokens_mistral': 2519, 'n_tokens_neox': 2474, 'n_words': 652}