<commit_before><?php

namespace Kregel\FormModel\Interfaces;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\Relations\MorphMany;
use Illuminate\Database\Eloquent\Relations\MorphOne;
use Illuminate\Database\Eloquent\Relations\MorphTo;
use Illuminate\Database\Eloquent\Relations\MorphToMany;
use Kregel\FormModel\Traits\Formable;

abstract class FrameworkInputs
{
    use Formable;
    /**
     * @var
     */
    public $model;
    /**
     * @var
     */
    public $vue_components;
    /**
     * @var
     */
    protected $location;

    /**
     * @var
     */
    protected $accessor = 'name';

    public function plainTextarea($options, $text = '')
    {
        return '<textarea'.$this->attributes($options).'>'.
        (is_string($text) ? $text : collect($text)).'</textarea>';
    }

    /**
     * This function builds attributes for html elements
     * ex.
     *      id="name".
     *
     * @param array $attr A key value pair of attributes
     *                    for an HTML Element
     *
     * @return string $attr_string
     */
    public function attributes(array $attr)
    {
        $attr_string = '';
        foreach ($attr as $name => $value) {
            if (is_array($value)) {
                $attr_string .= ' '.$name.'="'.implode(' ', $value).'"';
            } else {
                $attr_string .= ' '.$name.'="'.$value.'"';
            }
        }

        return $attr_string;
    }

    public function plainSelect($configs, $options)
    {
        if (!empty($configs['default'])) {
            $default = $configs['default'];

            unset($configs['default']);
        } else {
            $default = ' ';
        }
        $default_text = empty($configs['default_text']) ? '' : $configs['default_text'];

        return '<select'.$this->attributes($configs).'>'.
        '<option value="" disabled '.(is_numeric($default) ? '' : 'selected').'>'.$default_text."</option>\n"
        .$this->buildOptions($options, is_numeric($default) ? $default : false).
        "</select>\n";
    }

    public function buildOptions($options, $hasDefault = false)
    {
        $return = '';

        foreach ($options as $value => $text) {
            $attr = [];
            if ($hasDefault !== false && $value === $hasDefault) {
                $attr['selected'] = 'selected';
            }
            $attr['value'] = $value;
            $return .= '<option'.$this->attributes($attr).'>'.$text."</option>\n";
        }

        return $return;
    }

    public function plainSubmit(array $options = [])
    {
        return $this->input(array_merge(['type' => 'submit'], $options));
    }

    /**
     * @param array $options Should contain type, and name
     *
     * @return string html submit input
     */
    public function plainInput($options = [])
    {
        return '<input'.$this->attributes($options).'>';
    }

    /**
     * @param array $options
     *
     * @return string|html
     */
    public function form(array $options = [])
    {
        $method = empty($options['method']) ? $options['method'] : '';
        if (!in_array(strtolower($method), ['get', 'post'])) {
            $options['method'] = 'POST';
        }
        // Throw in all the attributes meant for the form
        return '<form '.$this->attributes($options['form']).'>'.
        $this->method($options['method']).
        $this->buildForm().
        $this->submit().'</form>';
    }

    public function method($method)
    {
        if ($method !== '' && $method !== null) {
            if (!in_array(strtolower($method), ['get', 'post'])) {
                return $this->input(['type' => 'hidden', 'name' => '_method', 'value' => $method]);
            }
        }

        return '';
    }

    public function csrf()
    {
        if (config('kregel.formmodel.using.csrf')) {
            return $this->input(['type' => 'hidden', 'name' => '_token', 'value' => csrf_token()]);
        }

        return '';
    }

    public function buildForm()
    {
        return $this->getFillable()->map(function ($input) {
            return ($input);
        })->implode('');
    }

    public function getFillable($model = null)
    {<commit_msg>Applied fixes from StyleCI (#20)<commit_after><?php

namespace Kregel\FormModel\Interfaces;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\Relations\MorphMany;
use Illuminate\Database\Eloquent\Relations\MorphOne;
use Illuminate\Database\Eloquent\Relations\MorphTo;
use Illuminate\Database\Eloquent\Relations\MorphToMany;
use Kregel\FormModel\Traits\Formable;

abstract class FrameworkInputs
{
    use Formable;
    /**
     * @var
     */
    public $model;
    /**
     * @var
     */
    public $vue_components;
    /**
     * @var
     */
    protected $location;

    /**
     * @var
     */
    protected $accessor = 'name';

    public function plainTextarea($options, $text = '')
    {
        return '<textarea'.$this->attributes($options).'>'.
        (is_string($text) ? $text : collect($text)).'</textarea>';
    }

    /**
     * This function builds attributes for html elements
     * ex.
     *      id="name".
     *
     * @param array $attr A key value pair of attributes
     *                    for an HTML Element
     *
     * @return string $attr_string
     */
    public function attributes(array $attr)
    {
        $attr_string = '';
        foreach ($attr as $name => $value) {
            if (is_array($value)) {
                $attr_string .= ' '.$name.'="'.implode(' ', $value).'"';
            } else {
                $attr_string .= ' '.$name.'="'.$value.'"';
            }
        }

        return $attr_string;
    }

    public function plainSelect($configs, $options)
    {
        if (!empty($configs['default'])) {
            $default = $configs['default'];

            unset($configs['default']);
        } else {
            $default = ' ';
        }
        $default_text = empty($configs['default_text']) ? '' : $configs['default_text'];

        return '<select'.$this->attributes($configs).'>'.
        '<option value="" disabled '.(is_numeric($default) ? '' : 'selected').'>'.$default_text."</option>\n"
        .$this->buildOptions($options, is_numeric($default) ? $default : false).
        "</select>\n";
    }

    public function buildOptions($options, $hasDefault = false)
    {
        $return = '';

        foreach ($options as $value => $text) {
            $attr = [];
            if ($hasDefault !== false && $value === $hasDefault) {
                $attr['selected'] = 'selected';
            }
            $attr['value'] = $value;
            $return .= '<option'.$this->attributes($attr).'>'.$text."</option>\n";
        }

        return $return;
    }

    public function plainSubmit(array $options = [])
    {
        return $this->input(array_merge(['type' => 'submit'], $options));
    }

    /**
     * @param array $options Should contain type, and name
     *
     * @return string html submit input
     */
    public function plainInput($options = [])
    {
        return '<input'.$this->attributes($options).'>';
    }

    /**
     * @param array $options
     *
     * @return string|html
     */
    public function form(array $options = [])
    {
        $method = empty($options['method']) ? $options['method'] : '';
        if (!in_array(strtolower($method), ['get', 'post'])) {
            $options['method'] = 'POST';
        }
        // Throw in all the attributes meant for the form
        return '<form '.$this->attributes($options['form']).'>'.
        $this->method($options['method']).
        $this->buildForm().
        $this->submit().'</form>';
    }

    public function method($method)
    {
        if ($method !== '' && $method !== null) {
            if (!in_array(strtolower($method), ['get', 'post'])) {
                return $this->input(['type' => 'hidden', 'name' => '_method', 'value' => $method]);
            }
        }

        return '';
    }

    public function csrf()
    {
        if (config('kregel.formmodel.using.csrf')) {
            return $this->input(['type' => 'hidden', 'name' => '_token', 'value' => csrf_token()]);
        }

        return '';
    }

    public function buildForm()
    {
        return $this->getFillable()->map(function ($input) {
            return $input;
        })->implode('');
    }

    public function getFillable($model = null)
    {
{'fraction_non_alphanumeric': 0.17571380205394424, 'fraction_numerical': 0.0002257081593499605, 'mean_word_length': 2.1571072319201994, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 73, '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': '243414', 'n_tokens_mistral': 2626, 'n_tokens_neox': 2610, 'n_words': 504}