Completed
Pull Request — master (#55)
by
unknown
03:47
created

Html::closeModelForm()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
namespace Spatie\Html;
4
5
use Spatie\Html\Elements\A;
6
use Illuminate\Http\Request;
7
use Spatie\Html\Elements\Div;
8
use Spatie\Html\Elements\File;
9
use Spatie\Html\Elements\Form;
10
use Spatie\Html\Elements\Span;
11
use Spatie\Html\Elements\Input;
12
use Spatie\Html\Elements\Label;
13
use Spatie\Html\Elements\Button;
14
use Spatie\Html\Elements\Legend;
15
use Spatie\Html\Elements\Option;
16
use Spatie\Html\Elements\Select;
17
use Spatie\Html\Elements\Element;
18
use Illuminate\Support\Collection;
19
use Illuminate\Support\HtmlString;
20
use Spatie\Html\Elements\Fieldset;
21
use Spatie\Html\Elements\Textarea;
22
use Illuminate\Support\Traits\Macroable;
23
use Illuminate\Contracts\Support\Htmlable;
24
25
class Html
26
{
27
    use Macroable;
28
29
    /** @var \Illuminate\Http\Request */
30
    protected $request;
31
32
    /** @var \ArrayAccess|array */
33
    protected $model;
34
35
    public function __construct(Request $request)
0 ignored issues
show
Bug introduced by
You have injected the Request via parameter $request. This is generally not recommended as there might be multiple instances during a request cycle (f.e. when using sub-requests). Instead, it is recommended to inject the RequestStack and retrieve the current request each time you need it via getCurrentRequest().
Loading history...
36
    {
37
        $this->request = $request;
38
    }
39
40
    /**
41
     * @param string|null $href
42
     * @param string|null $text
0 ignored issues
show
Bug introduced by
There is no parameter named $text. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
43
     *
44
     * @return \Spatie\Html\Elements\A
45
     */
46
    public function a($href = null, $contents = null)
47
    {
48
        return A::create()
49
            ->attributeIf($href, 'href', $href)
0 ignored issues
show
Documentation introduced by
$href is of type string|null, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
50
            ->html($contents);
51
    }
52
53
    /**
54
     * @param string|null $type
55
     * @param string|null $text
0 ignored issues
show
Bug introduced by
There is no parameter named $text. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
56
     *
57
     * @return \Spatie\Html\Elements\Button
58
     */
59
    public function button($contents = null, $type = null)
60
    {
61
        return Button::create()
62
            ->attributeIf($type, 'type', $type)
0 ignored issues
show
Documentation introduced by
$type is of type string|null, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
63
            ->html($contents);
64
    }
65
66
    /**
67
     * @param \Illuminate\Support\Collection|iterable|string $classes
68
     *
69
     * @return \Illuminate\Contracts\Support\Htmlable
70
     */
71
    public function class($classes): Htmlable
0 ignored issues
show
Coding Style introduced by
Possible parse error: non-abstract method defined as abstract
Loading history...
Coding Style introduced by
It is generally advisable to only define one property per statement.

Only declaring a single property per statement allows you to later on add doc comments more easily.

It is also recommended by PSR2, so it is a common style that many people expect.

Loading history...
72
    {
73
        if ($classes instanceof Collection) {
74
            $classes = $classes->toArray();
75
        }
76
77
        $attributes = new Attributes();
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $attributes.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
78
        $attributes->addClass($classes);
0 ignored issues
show
Coding Style introduced by
It is generally advisable to only define one property per statement.

Only declaring a single property per statement allows you to later on add doc comments more easily.

It is also recommended by PSR2, so it is a common style that many people expect.

Loading history...
Coding Style introduced by
The visibility should be declared for property $attributes.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
79
80
        return new HtmlString(
81
            $attributes->render()
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $attributes.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
82
        );
83
    }
84
85
    /**
86
     * @param string|null $name
87
     * @param bool $checked
88
     * @param string|null $value
89
     *
90
     * @return \Spatie\Html\Elements\Input
91
     */
92
    public function checkbox($name = null, $checked = false, $value = '1')
93
    {
94
        return $this->input('checkbox', $name, $value)
95
            ->attributeIf((bool) $this->old($name, $checked), 'checked');
96
    }
97
98
    /**
99
     * @param \Spatie\Html\HtmlElement|string|null $contents
100
     *
101
     * @return \Spatie\Html\Elements\Div
102
     */
103
    public function div($contents = null)
104
    {
105
        return Div::create()->children($contents);
106
    }
107
108
    /**
109
     * @param string|null $name
110
     * @param string|null $value
111
     *
112
     * @return \Spatie\Html\Elements\Input
113
     */
114
    public function email($name = '', $value = '')
115
    {
116
        return $this->input('email', $name, $value);
117
    }
118
119
    /**
120
     * @param string $tag
121
     *
122
     * @return \Spatie\Html\Elements\Element
123
     */
124
    public function element($tag)
125
    {
126
        return Element::withTag($tag);
127
    }
128
129
    /**
130
     * @param string|null $type
131
     * @param string|null $name
132
     * @param string|null $value
133
     *
134
     * @return \Spatie\Html\Elements\Input
135
     */
136
    public function input($type = null, $name = null, $value = null)
137
    {
138
        return Input::create()
139
            ->attributeIf($type, 'type', $type)
0 ignored issues
show
Documentation introduced by
$type is of type string|null, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
140
            ->attributeIf($name, 'name', $this->fieldName($name))
0 ignored issues
show
Documentation introduced by
$name is of type string|null, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
141
            ->attributeIf($name, 'id', $this->fieldName($name))
0 ignored issues
show
Documentation introduced by
$name is of type string|null, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
142
            ->attributeIf($name && $this->old($name, $value), 'value', $this->old($name, $value));
0 ignored issues
show
Bug introduced by
It seems like $this->old($name, $value) targeting Spatie\Html\Html::old() can also be of type array; however, Spatie\Html\BaseElement::attributeIf() does only seem to accept string|null, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
Bug Best Practice introduced by
The expression $name of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
143
    }
144
145
    /**
146
     * @param \Spatie\Html\HtmlElement|string|null $legend
147
     *
148
     * @return \Spatie\Html\Elements\Fieldset
149
     */
150
    public function fieldset($legend = null)
151
    {
152
        return $legend ?
153
            Fieldset::create()->legend($legend) :
154
            Fieldset::create();
155
    }
156
157
    /**
158
     * @param string $method
159
     * @param string|null $action
160
     *
161
     * @return \Spatie\Html\Elements\Form
162
     */
163
    public function form($method = 'POST', $action = null)
164
    {
165
        $method = strtoupper($method);
166
        $form = Form::create();
167
168
        // If Laravel needs to spoof the form's method, we'll append a hidden
169
        // field containing the actual method
170
        if (in_array($method, ['DELETE', 'PATCH', 'PUT'])) {
171
            $form = $form->addChild($this->hidden('_method')->value($method));
172
        }
173
174
        // On any other method that get, the form needs a CSRF token
175
        if ($method !== 'GET') {
176
            $form = $form->addChild($this->token());
177
        }
178
179
        return $form
180
            ->method($method === 'GET' ? 'GET' : 'POST')
181
            ->attributeIf($action, 'action', $action);
0 ignored issues
show
Documentation introduced by
$action is of type string|null, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
182
    }
183
184
    /**
185
     * @param string|null $name
186
     * @param string|null $value
187
     *
188
     * @return \Spatie\Html\Elements\Input
189
     */
190
    public function hidden($name = null, $value = null)
191
    {
192
        return $this->input('hidden', $name, $value);
193
    }
194
195
    /**
196
     * @param \Spatie\Html\HtmlElement|iterable|string|null $contents
197
     * @param string|null $for
198
     *
199
     * @return \Spatie\Html\Elements\Label
200
     */
201
    public function label($contents = null, $for = null)
202
    {
203
        return Label::create()
204
            ->attributeIf($for, 'for', $this->fieldName($for))
0 ignored issues
show
Documentation introduced by
$for is of type string|null, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
205
            ->children($contents);
206
    }
207
208
    /**
209
     * @param \Spatie\Html\HtmlElement|string|null $contents
210
     *
211
     * @return \Spatie\Html\Elements\Legend
212
     */
213
    public function legend($contents = null)
214
    {
215
        return Legend::create()->html($contents);
0 ignored issues
show
Bug introduced by
It seems like $contents defined by parameter $contents on line 213 can also be of type object<Spatie\Html\HtmlElement>; however, Spatie\Html\BaseElement::html() does only seem to accept string|null, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
216
    }
217
218
    /**
219
     * @param string $email
220
     * @param string|null $text
221
     *
222
     * @return \Spatie\Html\Elements\A
223
     */
224
    public function mailto($email, $text = null)
225
    {
226
        return $this->a('mailto:'.$email, $text);
227
    }
228
229
    /**
230
     * @param string|null $name
231
     * @param iterable $options
232
     * @param string|iterable|null $value
233
     *
234
     * @return \Spatie\Html\Elements\Select
235
     */
236 View Code Duplication
    public function multiselect($name = null, $options = [], $value = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
237
    {
238
        return Select::create()
239
            ->attributeIf($name, 'name', $this->fieldName($name))
0 ignored issues
show
Documentation introduced by
$name is of type string|null, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
240
            ->attributeIf($name, 'id', $this->fieldName($name))
0 ignored issues
show
Documentation introduced by
$name is of type string|null, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
241
            ->options($options)
0 ignored issues
show
Bug introduced by
It seems like $options defined by parameter $options on line 236 can also be of type array; however, Spatie\Html\Elements\Select::options() does only seem to accept object<Spatie\Html\Elements\iterable>, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
242
            ->value($name ? $this->old($name, $value) : $value)
243
            ->multiple();
244
    }
245
246
    /**
247
     * @param string|null $text
248
     * @param string|null $value
249
     * @param bool $selected
250
     *
251
     * @return \Spatie\Html\Elements\Option
252
     */
253
    public function option($text = null, $value = null, $selected = false)
254
    {
255
        return Option::create()
256
            ->text($text)
257
            ->value($value)
258
            ->selectedIf($selected);
259
    }
260
261
    /**
262
     * @param string|null $value
0 ignored issues
show
Bug introduced by
There is no parameter named $value. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
263
     *
264
     * @return \Spatie\Html\Elements\Input
265
     */
266
    public function password($name = null)
267
    {
268
        return $this->input('password', $name);
269
    }
270
271
    /**
272
     * @param string|null $name
273
     * @param bool $checked
274
     * @param string|null $value
275
     *
276
     * @return \Spatie\Html\Elements\Input
277
     */
278
    public function radio($name = null, $checked = false, $value = null)
279
    {
280
        return $this->input('radio', $name, $value)
281
            ->attributeIf((bool) $this->old($name, $checked), 'checked');
282
    }
283
284
    /**
285
     * @param string|null $name
286
     * @param iterable $options
287
     * @param string|iterable|null $value
288
     *
289
     * @return \Spatie\Html\Elements\Select
290
     */
291 View Code Duplication
    public function select($name = null, $options = [], $value = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
292
    {
293
        return Select::create()
294
            ->attributeIf($name, 'name', $this->fieldName($name))
0 ignored issues
show
Documentation introduced by
$name is of type string|null, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
295
            ->attributeIf($name, 'id', $this->fieldName($name))
0 ignored issues
show
Documentation introduced by
$name is of type string|null, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
296
            ->options($options)
0 ignored issues
show
Bug introduced by
It seems like $options defined by parameter $options on line 291 can also be of type array; however, Spatie\Html\Elements\Select::options() does only seem to accept object<Spatie\Html\Elements\iterable>, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
297
            ->value($name ? $this->old($name, $value) : $value);
298
    }
299
300
    /**
301
     * @param \Spatie\Html\HtmlElement|string|null $contents
302
     *
303
     * @return \Spatie\Html\Elements\Span
304
     */
305
    public function span($contents = null)
306
    {
307
        return Span::create()->children($contents);
308
    }
309
310
    /**
311
     * @param string|null $text
312
     *
313
     * @return \Spatie\Html\Elements\Button
314
     */
315
    public function submit($text = null)
316
    {
317
        return $this->button($text, 'submit');
318
    }
319
320
    /**
321
     * @param string|null $text
322
     *
323
     * @return \Spatie\Html\Elements\Button
324
     */
325
    public function reset($text = null)
326
    {
327
        return $this->button($text, 'reset');
328
    }
329
330
    /**
331
     * @param string $number
332
     * @param string|null $text
333
     *
334
     * @return \Spatie\Html\Elements\A
335
     */
336
    public function tel($number, $text = null)
337
    {
338
        return $this->a('tel:'.$number, $text);
339
    }
340
341
    /**
342
     * @param string|null $name
343
     * @param string|null $value
344
     *
345
     * @return \Spatie\Html\Elements\Input
346
     */
347
    public function text($name = null, $value = null)
348
    {
349
        return $this->input('text', $name, $value);
350
    }
351
352
    /**
353
     * @param string|null $name
354
     *
355
     * @return \Spatie\Html\Elements\File
356
     */
357
    public function file($name = null)
358
    {
359
        return File::create()
360
            ->attributeIf($name, 'name', $this->fieldName($name))
0 ignored issues
show
Documentation introduced by
$name is of type string|null, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
361
            ->attributeIf($name, 'id', $this->fieldName($name));
0 ignored issues
show
Documentation introduced by
$name is of type string|null, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
362
    }
363
364
    /**
365
     * @param string|null $name
366
     * @param string|null $value
367
     *
368
     * @return \Spatie\Html\Elements\Textarea
369
     */
370
    public function textarea($name = null, $value = null)
371
    {
372
        return Textarea::create()
373
            ->attributeIf($name, 'name', $this->fieldName($name))
0 ignored issues
show
Documentation introduced by
$name is of type string|null, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
374
            ->attributeIf($name, 'id', $this->fieldName($name))
0 ignored issues
show
Documentation introduced by
$name is of type string|null, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
375
            ->value($this->old($name, $value));
0 ignored issues
show
Bug introduced by
It seems like $this->old($name, $value) targeting Spatie\Html\Html::old() can also be of type array; however, Spatie\Html\Elements\Textarea::value() does only seem to accept string|null, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
376
    }
377
378
    /**
379
     * @return \Spatie\Html\Elements\Input
380
     */
381
    public function token()
382
    {
383
        return $this->hidden('_token')->value($this->request->session()->token());
0 ignored issues
show
Bug introduced by
The method token() does not seem to exist on object<Symfony\Component...ssion\SessionInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
384
    }
385
386
    /**
387
     * @param \ArrayAccess|array $model
388
     *
389
     * @return $this
390
     */
391
    public function model($model)
392
    {
393
        $this->model = $model;
394
395
        return $this;
396
    }
397
398
    /**
399
     * @param \ArrayAccess|array $model
400
     * @param string|null $method
401
     * @param string|null $action
402
     *
403
     * @return \Spatie\Html\Elements\Form
404
     */
405
    public function modelForm($model, $method = 'POST', $action = null): Form
406
    {
407
        $this->model($model);
408
409
        return $this->form($method, $action);
410
    }
411
412
    /**
413
     * @return $this
414
     */
415
    public function endModel()
416
    {
417
        $this->model = null;
418
419
        return $this;
420
    }
421
422
    /**
423
     * @return \Illuminate\Contracts\Support\Htmlable
424
     */
425
    public function closeModelForm(): Htmlable
426
    {
427
        $this->endModel();
428
429
        return $this->form()->close();
430
    }
431
432
    /**
433
     * @param string $name
434
     * @param mixed $value
435
     *
436
     * @return mixed
437
     */
438
    protected function old($name, $value = null)
439
    {
440
        if (empty($name)) {
441
            return;
442
        }
443
444
        // If there's no default value provided, and the html builder currently
445
        // has a model assigned, try to retrieve a value from the model.
446
        if (empty($value) && $this->model) {
447
            $value = $this->model[$name] ?? '';
448
        }
449
450
        return $this->request->old($name, $value);
451
    }
452
453
    /**
454
     * @param string $name
455
     *
456
     * @return string
457
     */
458
    protected function fieldName($name)
459
    {
460
        return $name;
461
    }
462
463
    protected function ensureModelIsAvailable()
464
    {
465
        if (empty($this->model)) {
466
            throw new Exception('Method requires a model to be set on the html builder');
467
        }
468
    }
469
}
470