Completed
Push — master ( d683c1...adb78f )
by Song
17s queued 11s
created

Text::datalist()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
1
<?php
2
3
namespace Encore\Admin\Form\Field;
4
5
use Encore\Admin\Form\Field;
6
7
class Text extends Field
8
{
9
    use PlainInput;
10
11
    /**
12
     * Render this filed.
13
     *
14
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
15
     */
16
    public function render()
17
    {
18
        $this->initPlainInput();
19
20
        $this->prepend('<i class="fa fa-pencil fa-fw"></i>')
21
            ->defaultAttribute('type', 'text')
22
            ->defaultAttribute('id', $this->id)
23
            ->defaultAttribute('name', $this->elementName ?: $this->formatName($this->column))
0 ignored issues
show
Bug introduced by
It seems like $this->column can also be of type array; however, Encore\Admin\Form\Field::formatName() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
24
            ->defaultAttribute('value', old($this->column, $this->value()))
0 ignored issues
show
Bug introduced by
It seems like $this->column can also be of type array; however, old() does only seem to accept string|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
25
            ->defaultAttribute('class', 'form-control '.$this->getElementClassString())
26
            ->defaultAttribute('placeholder', $this->getPlaceholder());
27
28
        $this->addVariables([
29
            'prepend' => $this->prepend,
30
            'append'  => $this->append,
31
        ]);
32
33
        return parent::render();
0 ignored issues
show
Bug Compatibility introduced by
The expression parent::render(); of type string|Illuminate\View\V...\Contracts\View\Factory adds the type Illuminate\Contracts\View\Factory to the return on line 33 which is incompatible with the return type declared by the interface Illuminate\Contracts\Support\Renderable::render of type string.
Loading history...
34
    }
35
36
    public function datalist( $entries = [] ) {
37
        $this->defaultAttribute('list', "list-{$this->id}");
38
        $datalist = "<datalist id=\"list-{$this->id}\">";
39
        foreach($entries as $k => $v) {
40
            $datalist .= "<option value=\"{$k}\">{$v}</option>";
41
        }
42
        $datalist .= "</datalist>";
43
        $this->append($datalist);
44
    }
45
}
46