Completed
Pull Request — master (#2953)
by
unknown
02:14
created

Text   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 48
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A addIcon() 0 6 1
A render() 0 19 2
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
     * @var string
13
     */
14
    protected $icon = 'fa-pencil';
15
16
    /**
17
     * Add custom fa-icon.
18
     *
19
     * @param string $icon
20
     *
21
     * @return $this
22
     */
23
    public function addIcon($icon)
24
    {
25
        $this->icon = $icon;
26
27
        return $this;
28
    }
29
30
    /**
31
     * Render this filed.
32
     *
33
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
34
     */
35
    public function render()
36
    {
37
        $this->initPlainInput();
38
39
        $this->prepend('<i class="fa '.$this->icon.' fa-fw"></i>')
40
            ->defaultAttribute('type', 'text')
41
            ->defaultAttribute('id', $this->id)
42
            ->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...
43
            ->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...
44
            ->defaultAttribute('class', 'form-control '.$this->getElementClassString())
45
            ->defaultAttribute('placeholder', $this->getPlaceholder());
46
47
        $this->addVariables([
48
            'prepend' => $this->prepend,
49
            'append'  => $this->append,
50
        ]);
51
52
        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 52 which is incompatible with the return type declared by the interface Illuminate\Contracts\Support\Renderable::render of type string.
Loading history...
53
    }
54
}
55