diff --git a/src/FormBuilder.php b/src/FormBuilder.php index 412c92d..6abee5b 100644 --- a/src/FormBuilder.php +++ b/src/FormBuilder.php @@ -124,10 +124,10 @@ class FormBuilder /** * Create a new form builder instance. * - * @param Factory $view - * @param string|null $csrfToken - * @param UrlGenerator|null $url - * @param Request|null $request + * @param Factory $view + * @param string|null $csrfToken + * @param UrlGenerator|null $url + * @param Request|null $request */ public function __construct(Factory $view, string $csrfToken = null, UrlGenerator $url = null, Request $request = null) { @@ -144,8 +144,8 @@ public function __construct(Factory $view, string $csrfToken = null, UrlGenerato /** * Dynamically handle calls to the class. * - * @param string $method - * @param array $parameters + * @param string $method + * @param array $parameters * @return mixed * * @throws BadMethodCallException @@ -177,7 +177,7 @@ public function getSessionStore(): Session /** * Set the session store implementation. * - * @param Session $session + * @param Session $session * @return $this */ public function setSessionStore(Session $session): self @@ -190,8 +190,8 @@ public function setSessionStore(Session $session): self /** * Create a new model based form builder. * - * @param mixed $model - * @param array $options + * @param mixed $model + * @param array $options * @return HtmlString */ public function model($model, array $options = []) @@ -205,7 +205,7 @@ public function model($model, array $options = []) * Open up a new HTML form. * Form::open() * - * @param array $options + * @param array $options * @return HtmlString */ public function open(array $options = []) @@ -244,13 +244,13 @@ public function open(array $options = []) // extra value for the hidden _method field if it's needed for the form. $attributes = $this->attributes($attributes); - return $this->toHtmlString('' . $append); + return $this->toHtmlString(''.$append); } /** * Parse the form action method. * - * @param string $method + * @param string $method * @return string */ protected function getMethod(string $method) @@ -263,7 +263,7 @@ protected function getMethod(string $method) /** * Get the form action from the options. * - * @param array $options + * @param array $options * @return string */ protected function getAction(array $options) @@ -292,7 +292,7 @@ protected function getAction(array $options) /** * Get the action for a "url" option. * - * @param array|string $options + * @param array|string $options * @return string */ protected function getUrlAction($options) @@ -307,7 +307,7 @@ protected function getUrlAction($options) /** * Get the action for a "route" option. * - * @param array|string $options + * @param array|string $options * @return string */ protected function getRouteAction($options) @@ -328,7 +328,7 @@ protected function getRouteAction($options) /** * Get the action for an "action" option. * - * @param array|string $options + * @param array|string $options * @return string */ protected function getControllerAction($options) @@ -343,7 +343,7 @@ protected function getControllerAction($options) /** * Get the form appendage for the given method. * - * @param string $method + * @param string $method * @return string */ protected function getAppendage(string $method) @@ -370,10 +370,10 @@ protected function getAppendage(string $method) /** * Create a hidden input field. * - * @param string $name - * @param null $value - * @param bool $required - * @param array $options + * @param string $name + * @param null $value + * @param bool $required + * @param array $options * @return HtmlString */ public function hidden(string $name, $value = null, bool $required = false, array $options = []) @@ -384,18 +384,18 @@ public function hidden(string $name, $value = null, bool $required = false, arra /** * Create a form input field. * - * @param string $type - * @param string $name - * @param null $value - * @param bool $required - * @param array $options + * @param string $type + * @param string $name + * @param null $value + * @param bool $required + * @param array $options * @return HtmlString */ public function input(string $type, string $name, $value = null, bool $required = false, array $options = []) { $this->type = $type; - if (!isset($options['name'])) { + if (! isset($options['name'])) { $options['name'] = $name; } @@ -417,7 +417,7 @@ public function input(string $type, string $name, $value = null, bool $required // in the model instance if one is set. Otherwise we will just use empty. $id = $this->getIdAttribute($name, $options); - if (!in_array($type, $this->skipValueTypes)) { + if (! in_array($type, $this->skipValueTypes)) { $value = $this->getValueAttribute($name, $value); } @@ -432,13 +432,13 @@ public function input(string $type, string $name, $value = null, bool $required $options['required'] = 'required'; } - return $this->toHtmlString('attributes($options) . '>'); + return $this->toHtmlString('attributes($options).'>'); } /** * @param $name - * @param array $options - * @param string $field + * @param array $options + * @param string $field */ protected function classAttributes($name, array &$options = [], string $field = 'field') { @@ -462,8 +462,8 @@ protected function classAttributes($name, array &$options = [], string $field = /** * Get the ID attribute for a field name. * - * @param string $name - * @param array $attributes + * @param string $name + * @param array $attributes * @return string|null */ protected function getIdAttribute(string $name, array $attributes): ?string @@ -482,8 +482,8 @@ protected function getIdAttribute(string $name, array $attributes): ?string /** * Get the value that should be assigned to the field. * - * @param string|null $name - * @param null $value + * @param string|null $name + * @param null $value * @return mixed */ protected function getValueAttribute(string $name = null, $value = null) @@ -494,7 +494,7 @@ protected function getValueAttribute(string $name = null, $value = null) $old = $this->old($name); - if (!is_null($old) && $name !== '_method') { + if (! is_null($old) && $name !== '_method') { return $old; } @@ -505,7 +505,7 @@ protected function getValueAttribute(string $name = null, $value = null) if ($hasNullMiddleware && is_null($old) && is_null($value) - && !is_null($this->view->shared('errors')) + && ! is_null($this->view->shared('errors')) && count(is_countable($this->view->shared('errors')) ? $this->view->shared('errors') : []) > 0 ) { return null; @@ -513,11 +513,11 @@ protected function getValueAttribute(string $name = null, $value = null) } $request = $this->request($name); - if (!is_null($request) && $name != '_method') { + if (! is_null($request) && $name != '_method') { return $request; } - if (!is_null($value)) { + if (! is_null($value)) { return $value; } @@ -531,7 +531,7 @@ protected function getValueAttribute(string $name = null, $value = null) /** * Get a value from the session's old input. * - * @param string $name + * @param string $name * @return mixed */ public function old(string $name) @@ -539,16 +539,16 @@ public function old(string $name) $key = $this->transformKey($name); $payload = $this->session->getOldInput($key); - if (!is_array($payload)) { + if (! is_array($payload)) { return $payload; } - if (!in_array($this->type, ['select', 'checkbox'])) { - if (!isset($this->payload[$key])) { + if (! in_array($this->type, ['select', 'checkbox'])) { + if (! isset($this->payload[$key])) { $this->payload[$key] = collect($payload); } - if (!empty($this->payload[$key])) { + if (! empty($this->payload[$key])) { return $this->payload[$key]->shift(); } } @@ -559,7 +559,7 @@ public function old(string $name) /** * Transform key from array to dot syntax. * - * @param string $key + * @param string $key * @return mixed */ protected function transformKey(string $key) @@ -575,11 +575,11 @@ protected function transformKey(string $key) */ protected function request($name) { - if (!$this->considerRequest) { + if (! $this->considerRequest) { return null; } - if (!isset($this->request)) { + if (! isset($this->request)) { return null; } @@ -589,7 +589,7 @@ protected function request($name) /** * Get the model value that should be assigned to the field. * - * @param string $name + * @param string $name * @return mixed */ protected function getModelValueAttribute(string $name) @@ -617,14 +617,14 @@ protected function toHtmlString($html) /** * Build an HTML attribute string from an array. * - * @param array $attributes + * @param array $attributes * @return string */ protected function attributes(array $attributes) { $html = []; - foreach ((array)$attributes as $key => $value) { + foreach ((array) $attributes as $key => $value) { $element = $this->attributeElement($key, $value); if ($element != null) { @@ -632,14 +632,14 @@ protected function attributes(array $attributes) } } - return count($html) > 0 ? ' ' . implode(' ', $html) : ''; + return count($html) > 0 ? ' '.implode(' ', $html) : ''; } /** * Build a single attribute element. * - * @param string $key - * @param mixed $value + * @param string $key + * @param mixed $value * @return string */ private function attributeElement(string $key, $value) @@ -654,11 +654,11 @@ private function attributeElement(string $key, $value) } if (is_array($value) && $key === 'class') { - return 'class="' . implode(' ', $value) . '"'; + return 'class="'.implode(' ', $value).'"'; } - if (!is_null($value)) { - return $key . '="' . e($value, false) . '"'; + if (! is_null($value)) { + return $key.'="'.e($value, false).'"'; } return ''; @@ -671,7 +671,7 @@ private function attributeElement(string $key, $value) */ public function token() { - $token = !empty($this->csrfToken) ? $this->csrfToken : $this->session->token(); + $token = ! empty($this->csrfToken) ? $this->csrfToken : $this->session->token(); return $this->hidden('_token', $token); } @@ -689,7 +689,7 @@ public function getModel() /** * Set the model instance on the form builder. * - * @param mixed $model + * @param mixed $model * @return void */ public function setModel($model) @@ -714,11 +714,11 @@ public function close() /** * Create a form label element. * - * @param string $name - * @param null $title - * @param bool $required - * @param array $options - * @param bool $escape_html + * @param string $name + * @param null $title + * @param bool $required + * @param array $options + * @param bool $escape_html * @return HtmlString */ public function label(string $name, $title = null, bool $required = false, array $options = [], $escape_html = true) @@ -743,7 +743,7 @@ public function label(string $name, $title = null, bool $required = false, array } if ($required) { - $title = $title . '*'; + $title = $title.'*'; } return $this->toHtmlString(""); @@ -752,10 +752,10 @@ public function label(string $name, $title = null, bool $required = false, array /** * Create a text input field. * - * @param string $name - * @param null $value - * @param bool $required - * @param array $options + * @param string $name + * @param null $value + * @param bool $required + * @param array $options * @return HtmlString */ public function text(string $name, $value = null, bool $required = false, array $options = []) @@ -766,9 +766,9 @@ public function text(string $name, $value = null, bool $required = false, array /** * Create a password input field. * - * @param string $name - * @param bool $required - * @param array $options + * @param string $name + * @param bool $required + * @param array $options * @return HtmlString */ public function password(string $name, bool $required = false, array $options = []) @@ -779,10 +779,10 @@ public function password(string $name, bool $required = false, array $options = /** * Create a range input field. * - * @param string $name - * @param null $value - * @param bool $required - * @param array $options + * @param string $name + * @param null $value + * @param bool $required + * @param array $options * @return HtmlString */ public function range(string $name, $value = null, bool $required = false, array $options = []) @@ -795,10 +795,10 @@ public function range(string $name, $value = null, bool $required = false, array /** * Create a search input field. * - * @param string $name - * @param null $value - * @param bool $required - * @param array $options + * @param string $name + * @param null $value + * @param bool $required + * @param array $options * @return HtmlString */ public function search(string $name, $value = null, bool $required = false, array $options = []) @@ -809,10 +809,10 @@ public function search(string $name, $value = null, bool $required = false, arra /** * Create an e-mail input field. * - * @param string $name - * @param null $value - * @param bool $required - * @param array $options + * @param string $name + * @param null $value + * @param bool $required + * @param array $options * @return HtmlString */ public function email(string $name, $value = null, bool $required = false, array $options = []) @@ -823,10 +823,10 @@ public function email(string $name, $value = null, bool $required = false, array /** * Create a tel input field. * - * @param string $name - * @param null $value - * @param bool $required - * @param array $options + * @param string $name + * @param null $value + * @param bool $required + * @param array $options * @return HtmlString */ public function tel(string $name, $value = null, bool $required = false, array $options = []) @@ -837,10 +837,10 @@ public function tel(string $name, $value = null, bool $required = false, array $ /** * Create a number input field. * - * @param string $name - * @param null $value - * @param bool $required - * @param array $options + * @param string $name + * @param null $value + * @param bool $required + * @param array $options * @return HtmlString */ public function number(string $name, $value = null, bool $required = false, array $options = []) @@ -851,10 +851,10 @@ public function number(string $name, $value = null, bool $required = false, arra /** * Create a date input field. * - * @param string $name - * @param mixed $value - * @param bool $required - * @param array $options + * @param string $name + * @param mixed $value + * @param bool $required + * @param array $options * @return HtmlString */ public function date(string $name, $value = null, bool $required = false, array $options = []) @@ -869,10 +869,10 @@ public function date(string $name, $value = null, bool $required = false, array /** * Create a datetime input field. * - * @param string $name - * @param mixed $value - * @param bool $required - * @param array $options + * @param string $name + * @param mixed $value + * @param bool $required + * @param array $options * @return HtmlString */ public function datetime(string $name, $value = null, bool $required = false, array $options = []) @@ -887,10 +887,10 @@ public function datetime(string $name, $value = null, bool $required = false, ar /** * Create a datetime-local input field. * - * @param string $name - * @param mixed $value - * @param bool $required - * @param array $options + * @param string $name + * @param mixed $value + * @param bool $required + * @param array $options * @return HtmlString */ public function datetimeLocal(string $name, $value = null, bool $required = false, array $options = []) @@ -905,10 +905,10 @@ public function datetimeLocal(string $name, $value = null, bool $required = fals /** * Create a time input field. * - * @param string $name - * @param mixed $value - * @param bool $required - * @param array $options + * @param string $name + * @param mixed $value + * @param bool $required + * @param array $options * @return HtmlString */ public function time(string $name, $value = null, bool $required = false, array $options = []) @@ -923,10 +923,10 @@ public function time(string $name, $value = null, bool $required = false, array /** * Create a url input field. * - * @param string $name - * @param null $value - * @param bool $required - * @param array $options + * @param string $name + * @param null $value + * @param bool $required + * @param array $options * @return HtmlString */ public function url(string $name, $value = null, bool $required = false, array $options = []) @@ -937,10 +937,10 @@ public function url(string $name, $value = null, bool $required = false, array $ /** * Create a week input field. * - * @param string $name - * @param mixed $value - * @param bool $required - * @param array $options + * @param string $name + * @param mixed $value + * @param bool $required + * @param array $options * @return HtmlString */ public function week(string $name, $value = null, bool $required = false, array $options = []) @@ -955,9 +955,9 @@ public function week(string $name, $value = null, bool $required = false, array /** * Create a file input field. * - * @param string $name - * @param bool $required - * @param array $options + * @param string $name + * @param bool $required + * @param array $options * @return HtmlString */ public function file(string $name, bool $required = false, array $options = []) @@ -970,17 +970,17 @@ public function file(string $name, bool $required = false, array $options = []) /** * Create a textarea input field. * - * @param string $name - * @param null $value - * @param bool $required - * @param array $options + * @param string $name + * @param null $value + * @param bool $required + * @param array $options * @return HtmlString */ public function textarea(string $name, $value = null, bool $required = false, array $options = []) { $this->type = 'textarea'; - if (!isset($options['name'])) { + if (! isset($options['name'])) { $options['name'] = $name; } @@ -988,24 +988,24 @@ public function textarea(string $name, $value = null, bool $required = false, ar $options['id'] = $this->getIdAttribute($name, $options); - $value = (string)$this->getValueAttribute($name, $value); + $value = (string) $this->getValueAttribute($name, $value); if ($required === true) { $options['required'] = 'required'; } - return $this->toHtmlString('attributes($options) . '>' . e($value, false) . ''); + return $this->toHtmlString('attributes($options).'>'.e($value, false).''); } /** * Create a select year field. * - * @param string $name - * @param mixed $begin - * @param mixed $end - * @param string|null $selected - * @param bool $required - * @param array $options + * @param string $name + * @param mixed $begin + * @param mixed $end + * @param string|null $selected + * @param bool $required + * @param array $options * @return HtmlString */ public function selectYear(string $name, $begin, $end, string $selected = null, bool $required = false, array $options = []) @@ -1016,12 +1016,12 @@ public function selectYear(string $name, $begin, $end, string $selected = null, /** * Create a select range field. * - * @param string $name - * @param string $begin - * @param string $end - * @param null $selected - * @param bool $required - * @param array $options + * @param string $name + * @param string $begin + * @param string $end + * @param null $selected + * @param bool $required + * @param array $options * @return HtmlString */ public function selectRange(string $name, $begin, $end, $selected = null, bool $required = false, array $options = []) @@ -1041,13 +1041,13 @@ public function selectRange(string $name, $begin, $end, $selected = null, bool $ /** * Create a select box field. * - * @param string $name - * @param array $list - * @param null $selected - * @param bool $required - * @param array $selectAttributes - * @param array $optionsAttributes - * @param array $optgroupsAttributes + * @param string $name + * @param array $list + * @param null $selected + * @param bool $required + * @param array $selectAttributes + * @param array $optionsAttributes + * @param array $optgroupsAttributes * @return HtmlString */ public function select( @@ -1058,8 +1058,7 @@ public function select( array $selectAttributes = [], array $optionsAttributes = [], array $optgroupsAttributes = [] - ) - { + ) { $this->type = 'select'; $this->classAttributes($name, $selectAttributes, 'field'); @@ -1070,7 +1069,7 @@ public function select( $selectAttributes['id'] = $this->getIdAttribute($name, $selectAttributes); - if (!isset($selectAttributes['name'])) { + if (! isset($selectAttributes['name'])) { $selectAttributes['name'] = $name; } @@ -1119,39 +1118,39 @@ protected function placeholderOption($display, $selected) 'value' => '', ]; - return $this->toHtmlString('attributes($options) . '>' . e($display, false) . ''); + return $this->toHtmlString('attributes($options).'>'.e($display, false).''); } /** * Determine if the value is selected. * - * @param string|null $value - * @param mixed $selected + * @param string|null $value + * @param mixed $selected * @return mixed */ protected function getSelectedValue($value, $selected) { if (is_array($selected)) { - return in_array($value, $selected, true) || in_array((string)$value, $selected, true) ? 'selected' : null; + return in_array($value, $selected, true) || in_array((string) $value, $selected, true) ? 'selected' : null; } elseif ($selected instanceof Collection) { return $selected->contains($value) ? 'selected' : null; } /** @phpstan-ignore-next-line */ if (is_int($value) && is_bool($selected)) { - return (bool)$value === $selected; + return (bool) $value === $selected; } - return ((string)$value === (string)$selected) ? 'selected' : null; + return ((string) $value === (string) $selected) ? 'selected' : null; } /** * Get the select option for the given value. * - * @param mixed $display - * @param string $value - * @param string|null $selected - * @param array $attributes - * @param array $optgroupAttributes + * @param mixed $display + * @param string $value + * @param string|null $selected + * @param array $attributes + * @param array $optgroupAttributes * @return HtmlString */ protected function getSelectOption($display, string $value, $selected = null, array $attributes = [], array $optgroupAttributes = []) @@ -1166,12 +1165,12 @@ protected function getSelectOption($display, string $value, $selected = null, ar /** * Create an option group form element. * - * @param array $list - * @param string $label - * @param string $selected - * @param array $attributes - * @param array $optionsAttributes - * @param int $level + * @param array $list + * @param string $label + * @param string $selected + * @param array $attributes + * @param array $optionsAttributes + * @param int $level * @return HtmlString */ protected function optionGroup(array $list, string $label, string $selected, array $attributes = [], array $optionsAttributes = [], $level = 0) @@ -1183,20 +1182,20 @@ protected function optionGroup(array $list, string $label, string $selected, arr if (is_iterable($display)) { $html[] = $this->optionGroup($display, $value, $selected, $attributes, $optionAttributes, $level + 5); } else { - $html[] = $this->option($space . $display, $value, $selected, $optionAttributes); + $html[] = $this->option($space.$display, $value, $selected, $optionAttributes); } } - return $this->toHtmlString('attributes($attributes) . '>' . implode('', $html) . ''); + return $this->toHtmlString('attributes($attributes).'>'.implode('', $html).''); } /** * Create a select element option. * - * @param string $display - * @param string $value - * @param string|null $selected - * @param array $attributes + * @param string $display + * @param string $value + * @param string|null $selected + * @param array $attributes * @return HtmlString */ protected function option(string $display, string $value, $selected = null, array $attributes = []) @@ -1205,9 +1204,9 @@ protected function option(string $display, string $value, $selected = null, arra $options = array_merge(['value' => $value, 'selected' => $selected], $attributes); - $string = 'attributes($options) . '>'; + $string = 'attributes($options).'>'; if ($display !== null) { - $string .= e($display, false) . ''; + $string .= e($display, false).''; } return $this->toHtmlString($string); @@ -1216,10 +1215,10 @@ protected function option(string $display, string $value, $selected = null, arra /** * Create a select month field. * - * @param string $name - * @param null $selected - * @param bool $required - * @param array $options + * @param string $name + * @param null $selected + * @param bool $required + * @param array $options * @return HtmlString */ public function selectMonth(string $name, $selected = null, bool $required = false, array $options = []) @@ -1245,11 +1244,11 @@ public function selectMonth(string $name, $selected = null, bool $required = fal /** * Create a checkbox input field. * - * @param string $name - * @param mixed $value - * @param null $checked - * @param bool $required - * @param array $options + * @param string $name + * @param mixed $value + * @param null $checked + * @param bool $required + * @param array $options * @return HtmlString */ public function checkbox(string $name, $value = 1, $checked = null, bool $required = false, array $options = []) @@ -1260,12 +1259,12 @@ public function checkbox(string $name, $value = 1, $checked = null, bool $requir /** * Create a checkable input field. * - * @param string $type - * @param string $name - * @param mixed $value - * @param bool $checked - * @param bool $required - * @param array $options + * @param string $type + * @param string $name + * @param mixed $value + * @param bool $checked + * @param bool $required + * @param array $options * @return HtmlString */ protected function checkable(string $type, string $name, $value, bool $checked, bool $required = false, array $options = []) @@ -1284,10 +1283,10 @@ protected function checkable(string $type, string $name, $value, bool $checked, /** * Get the check state for a checkable input. * - * @param string $type - * @param string $name - * @param mixed $value - * @param bool $checked + * @param string $type + * @param string $name + * @param mixed $value + * @param bool $checked * @return bool */ protected function getCheckedState(string $type, string $name, $value, bool $checked): bool @@ -1307,16 +1306,16 @@ protected function getCheckedState(string $type, string $name, $value, bool $che /** * Get the check state for a checkbox input. * - * @param string $name - * @param mixed $value - * @param bool $checked + * @param string $name + * @param mixed $value + * @param bool $checked * @return bool */ protected function getCheckboxCheckedState(string $name, $value, bool $checked): bool { $request = $this->request($name); - if (!$this->oldInputIsEmpty() && is_null($this->old($name)) && !$request) { + if (! $this->oldInputIsEmpty() && is_null($this->old($name)) && ! $request) { return false; } @@ -1331,7 +1330,7 @@ protected function getCheckboxCheckedState(string $name, $value, bool $checked): } elseif ($posted instanceof Collection) { return $posted->contains('id', $value); } else { - return (bool)$posted; + return (bool) $posted; } } @@ -1342,13 +1341,13 @@ protected function getCheckboxCheckedState(string $name, $value, bool $checked): */ private function oldInputIsEmpty(): bool { - return count((array)$this->session->getOldInput()) === 0; + return count((array) $this->session->getOldInput()) === 0; } /** * Determine if old input or model input exists for a key. * - * @param string $name + * @param string $name * @return bool */ protected function missingOldAndModel(string $name): bool @@ -1359,16 +1358,16 @@ protected function missingOldAndModel(string $name): bool /** * Get the check state for a radio input. * - * @param string $name - * @param mixed $value - * @param bool $checked + * @param string $name + * @param mixed $value + * @param bool $checked * @return bool */ protected function getRadioCheckedState(string $name, $value, bool $checked): bool { $request = $this->request($name); - if ($this->missingOldAndModel($name) && !$request) { + if ($this->missingOldAndModel($name) && ! $request) { return $checked; } @@ -1380,8 +1379,8 @@ protected function getRadioCheckedState(string $name, $value, bool $checked): bo * Use loose comparison because Laravel model casting may be in affect and therefore * 1 == true and 0 == false. * - * @param string $name - * @param string $value + * @param string $name + * @param string $value * @return bool */ protected function compareValues(string $name, string $value): bool @@ -1392,11 +1391,11 @@ protected function compareValues(string $name, string $value): bool /** * Create a radio button input field. * - * @param string $name - * @param mixed $value - * @param bool $checked - * @param bool $required - * @param array $options + * @param string $name + * @param mixed $value + * @param bool $checked + * @param bool $required + * @param array $options * @return HtmlString */ public function radio(string $name, $value = null, bool $checked = false, bool $required = false, array $options = []) @@ -1411,8 +1410,8 @@ public function radio(string $name, $value = null, bool $checked = false, bool $ /** * Create a HTML reset input element. * - * @param string $value - * @param array $attributes + * @param string $value + * @param array $attributes * @return HtmlString */ public function reset(string $value, $attributes = []) @@ -1423,10 +1422,10 @@ public function reset(string $value, $attributes = []) /** * Create a HTML image input element. * - * @param string $url - * @param null $name - * @param bool $required - * @param array $attributes + * @param string $url + * @param null $name + * @param bool $required + * @param array $attributes * @return HtmlString */ public function image(string $url, $name = null, bool $required = false, $attributes = []) @@ -1439,10 +1438,10 @@ public function image(string $url, $name = null, bool $required = false, $attrib /** * Create a month input field. * - * @param string $name - * @param mixed $value - * @param bool $required - * @param array $options + * @param string $name + * @param mixed $value + * @param bool $required + * @param array $options * @return HtmlString */ public function month(string $name, $value = null, bool $required = false, array $options = []) @@ -1457,10 +1456,10 @@ public function month(string $name, $value = null, bool $required = false, array /** * Create a color input field. * - * @param string $name - * @param null $value - * @param bool $required - * @param array $options + * @param string $name + * @param null $value + * @param bool $required + * @param array $options * @return HtmlString */ public function color(string $name, $value = null, bool $required = false, array $options = []) @@ -1471,10 +1470,10 @@ public function color(string $name, $value = null, bool $required = false, array /** * Create a submit button element. * - * @param string $name - * @param null $value - * @param bool $button - * @param array $options + * @param string $name + * @param null $value + * @param bool $button + * @param array $options * @return HtmlString */ public function submit($name = 'submit', $value = null, $button = false, array $options = []) @@ -1494,24 +1493,24 @@ public function submit($name = 'submit', $value = null, $button = false, array $ /** * Create a button element. * - * @param string $value - * @param array $options + * @param string $value + * @param array $options * @return HtmlString */ public function button($value = null, array $options = []) { - if (!array_key_exists('type', $options)) { + if (! array_key_exists('type', $options)) { $options['type'] = 'button'; } - return $this->toHtmlString('attributes($options) . '>' . $value . ''); + return $this->toHtmlString('attributes($options).'>'.$value.''); } /** * Create a datalist box field. * - * @param string $id - * @param array $list + * @param string $id + * @param array $list * @return HtmlString */ public function datalist(string $id, $list = []) @@ -1542,7 +1541,7 @@ public function datalist(string $id, $list = []) /** * Determine if an array is associative. * - * @param array $array + * @param array $array * @return bool */ protected function isAssociativeArray(array $array): bool @@ -1553,9 +1552,9 @@ protected function isAssociativeArray(array $array): bool /** * Create a form error display element. * - * @param string $name - * @param bool $all - * @param array $options + * @param string $name + * @param bool $all + * @param array $options * @return HtmlString */ public function error(string $name, bool $all = false, array $options = []) @@ -1570,14 +1569,13 @@ public function error(string $name, bool $all = false, array $options = []) } /** - * @param string $name - * @param bool $list - * @param array $options + * @param string $name + * @param bool $list + * @param array $options * @return HtmlString */ protected function getErrorMessage(string $name, bool $list = false, array $options = []) { - $errors = ($this->request->hasSession()) ? $this->request->session()->get('errors') : new ViewErrorBag; @@ -1606,7 +1604,7 @@ protected function getErrorMessage(string $name, bool $list = false, array $opti /** * Set the text area size using the quick "size" attribute. * - * @param array $options + * @param array $options * @return array */ protected function setQuickTextAreaSize(array $options): array @@ -1619,7 +1617,7 @@ protected function setQuickTextAreaSize(array $options): array /** * Take Request in fill process * - * @param bool $consider + * @param bool $consider */ protected function considerRequest(bool $consider = true) { diff --git a/src/Providers/RegularFieldServiceProvider.php b/src/Providers/RegularFieldServiceProvider.php index ccd9c6e..16bb448 100644 --- a/src/Providers/RegularFieldServiceProvider.php +++ b/src/Providers/RegularFieldServiceProvider.php @@ -34,42 +34,42 @@ public function boot() { $style = Config::get('form.style', 'bootstrap4'); - Form::component('rText', 'form::' . $style . '.regular.text', ['name', 'label', 'default' => null, 'required' => false, 'attributes' => []]); + Form::component('rText', 'form::'.$style.'.regular.text', ['name', 'label', 'default' => null, 'required' => false, 'attributes' => []]); - Form::component('rEmail', 'form::' . $style . '.regular.email', ['name', 'label', 'default' => null, 'required' => false, 'attributes' => []]); + Form::component('rEmail', 'form::'.$style.'.regular.email', ['name', 'label', 'default' => null, 'required' => false, 'attributes' => []]); - Form::component('rPassword', 'form::' . $style . '.regular.password', ['name', 'label', 'required' => false, 'attributes' => []]); + Form::component('rPassword', 'form::'.$style.'.regular.password', ['name', 'label', 'required' => false, 'attributes' => []]); - Form::component('rRange', 'form::' . $style . '.regular.range', ['name', 'label', 'default' => null, 'required' => false, 'attributes' => []]); + Form::component('rRange', 'form::'.$style.'.regular.range', ['name', 'label', 'default' => null, 'required' => false, 'attributes' => []]); - Form::component('rSearch', 'form::' . $style . '.regular.search', ['name', 'label', 'default' => null, 'required' => false, 'attributes' => []]); + Form::component('rSearch', 'form::'.$style.'.regular.search', ['name', 'label', 'default' => null, 'required' => false, 'attributes' => []]); - Form::component('rTel', 'form::' . $style . '.regular.tel', ['name', 'label', 'default' => null, 'required' => false, 'attributes' => []]); + Form::component('rTel', 'form::'.$style.'.regular.tel', ['name', 'label', 'default' => null, 'required' => false, 'attributes' => []]); - Form::component('rNumber', 'form::' . $style . '.regular.number', ['name', 'label', 'default' => null, 'required' => false, 'attributes' => []]); + Form::component('rNumber', 'form::'.$style.'.regular.number', ['name', 'label', 'default' => null, 'required' => false, 'attributes' => []]); - Form::component('rDate', 'form::' . $style . '.regular.date', ['name', 'label', 'default' => date('Y-m-d'), 'required' => false, 'attributes' => []]); + Form::component('rDate', 'form::'.$style.'.regular.date', ['name', 'label', 'default' => date('Y-m-d'), 'required' => false, 'attributes' => []]); - Form::component('rUrl', 'form::' . $style . '.regular.url', ['name', 'label', 'default' => null, 'required' => false, 'attributes' => []]); + Form::component('rUrl', 'form::'.$style.'.regular.url', ['name', 'label', 'default' => null, 'required' => false, 'attributes' => []]); - Form::component('rFile', 'form::' . $style . '.regular.file', ['name', 'label', 'required' => false, 'attributes' => []]); + Form::component('rFile', 'form::'.$style.'.regular.file', ['name', 'label', 'required' => false, 'attributes' => []]); - Form::component('rImage', 'form::' . $style . '.regular.image', ['name', 'label', 'required' => false, 'preview' => ['preview' => false, 'height' => 100, 'default' => '/img/logo-app.png'], 'attributes' => ['accept' => 'image/*']]); + Form::component('rImage', 'form::'.$style.'.regular.image', ['name', 'label', 'required' => false, 'preview' => ['preview' => false, 'height' => 100, 'default' => '/img/logo-app.png'], 'attributes' => ['accept' => 'image/*']]); - Form::component('rTextarea', 'form::' . $style . '.regular.textarea', ['name', 'label', 'default' => null, 'required' => false, 'attributes' => []]); + Form::component('rTextarea', 'form::'.$style.'.regular.textarea', ['name', 'label', 'default' => null, 'required' => false, 'attributes' => []]); - Form::component('rSelect', 'form::' . $style . '.regular.select', ['name', 'label', 'data' => [], 'selected', 'required' => false, 'attributes' => []]); + Form::component('rSelect', 'form::'.$style.'.regular.select', ['name', 'label', 'data' => [], 'selected', 'required' => false, 'attributes' => []]); - Form::component('rSelectMulti', 'form::' . $style . '.regular.selectmulti', ['name', 'label', 'data' => [], 'selected' => [], 'required' => false, 'attributes' => []]); + Form::component('rSelectMulti', 'form::'.$style.'.regular.selectmulti', ['name', 'label', 'data' => [], 'selected' => [], 'required' => false, 'attributes' => []]); - Form::component('rSelectRange', 'form::' . $style . '.regular.selectrange', ['name', 'label', 'begin', 'end', 'selected', 'required' => false, 'attributes' => []]); + Form::component('rSelectRange', 'form::'.$style.'.regular.selectrange', ['name', 'label', 'begin', 'end', 'selected', 'required' => false, 'attributes' => []]); - Form::component('rSelectMonth', 'form::' . $style . '.regular.selectmonth', ['name', 'label', 'selected' => null, 'required' => false, 'attributes' => []]); + Form::component('rSelectMonth', 'form::'.$style.'.regular.selectmonth', ['name', 'label', 'selected' => null, 'required' => false, 'attributes' => []]); - Form::component('rSelectYear', 'form::' . $style . '.regular.selectyear', ['name', 'label', 'begin' => 1901, 'end' => date('Y'), 'selected' => null, 'required' => false, 'attributes' => []]); + Form::component('rSelectYear', 'form::'.$style.'.regular.selectyear', ['name', 'label', 'begin' => 1901, 'end' => date('Y'), 'selected' => null, 'required' => false, 'attributes' => []]); - Form::component('rCheckbox', 'form::' . $style . '.regular.checkbox', ['name', 'label', 'values' => [], 'checked' => [], 'required' => false, 'attributes' => []]); + Form::component('rCheckbox', 'form::'.$style.'.regular.checkbox', ['name', 'label', 'values' => [], 'checked' => [], 'required' => false, 'attributes' => []]); - Form::component('rRadio', 'form::' . $style . '.regular.radio', ['name', 'label', 'values' => [], 'checked' => null, 'required' => false, 'attributes' => []]); + Form::component('rRadio', 'form::'.$style.'.regular.radio', ['name', 'label', 'values' => [], 'checked' => null, 'required' => false, 'attributes' => []]); } } diff --git a/tests/Unit/RegularFormTest.php b/tests/Unit/RegularFormTest.php index 055cb16..9a3749e 100644 --- a/tests/Unit/RegularFormTest.php +++ b/tests/Unit/RegularFormTest.php @@ -1,11 +1,8 @@ assertIsObject($result); } - public function test_regular_email_field() { $result = Form::rEmail('Name', 'name', null, true, []); $this->assertIsObject($result); } - public function test_regular_password_field() { $result = Form::rPassword('Name', 'name', true, []); $this->assertIsObject($result); } - public function test_regular_range_field() { $result = Form::rRange('Name', 'name', null, true, []); $this->assertIsObject($result); } - public function test_regular_search_field() { $this->startSession(); @@ -58,77 +50,66 @@ public function test_regular_search_field() $this->assertIsObject($result); } - public function test_regular_tel_field() { $result = Form::rTel('Name', 'name', null, true, []); $this->assertIsObject($result); } - public function test_regular_number_field() { $result = Form::rNumber('Name', 'name', null, true, []); $this->assertIsObject($result); } - public function test_regular_date_field() { $result = Form::rDate('Name', 'name', null, true, []); $this->assertIsObject($result); } - public function test_regular_url_field() { $result = Form::rUrl('Name', 'name', null, true, []); $this->assertIsObject($result); } - public function test_regular_file_field() { $result = Form::rFile('Name', 'name', true, []); $this->assertIsObject($result); } - public function test_regular_image_field() { $result = Form::rImage('Name', 'name', true, []); $this->assertIsObject($result); } - public function test_regular_textarea_field() { $result = Form::rTextarea('Name', 'name', null, true, []); $this->assertIsObject($result); } - public function test_regular_select_field() { $result = Form::rSelect('Name', 'name', [], null, true, []); $this->assertIsObject($result); } - public function test_regular_select_multi_field() { $result = Form::rSelectMulti('Name', 'name', [], null, true, []); $this->assertIsObject($result); } - public function test_regular_select_range_field() { $result = Form::rSelectRange('Name', 'name', 1, 10, null, true, []); $this->assertIsObject($result); } - public function test_regular_select_month_field() { $result = Form::rSelectMonth('Name', 'name', null, true, []); @@ -141,19 +122,15 @@ public function test_regular_select_year_field() $this->assertIsObject($result); } - public function test_regular_checkbox_field() { $result = Form::rCheckbox('Name', 'name', [], null, true, []); $this->assertIsObject($result); } - public function test_regular_radio_field() { $result = Form::rRadio('Name', 'name', [], null, true, []); $this->assertIsObject($result); } - } -