Completed
Push — master ( 82be35...1537c0 )
by Song
02:28
created

src/Form/Field/Textarea.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Encore\Admin\Form\Field;
4
5
use Encore\Admin\Admin;
6
use Encore\Admin\Form\Field;
7
8
class Textarea extends Field
9
{
10
    use HasValuePicker;
11
12
    /**
13
     * Default rows of textarea.
14
     *
15
     * @var int
16
     */
17
    protected $rows = 5;
18
19
    /**
20
     * @var string
21
     */
22
    protected $append = '';
23
24
    /**
25
     * Set rows of textarea.
26
     *
27
     * @param int $rows
28
     *
29
     * @return $this
30
     */
31
    public function rows($rows = 5)
32
    {
33
        $this->rows = $rows;
34
35
        return $this;
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function render()
42
    {
43
        if (!$this->shouldRender()) {
44
            return '';
45
        }
46
47
        if (is_array($this->value)) {
48
            $this->value = json_encode($this->value, JSON_PRETTY_PRINT);
49
        }
50
51
        $this->mountPicker(function ($btn) {
52
            $this->addPickBtn($btn);
53
        });
54
55
        return parent::render()->with([
0 ignored issues
show
The method with does only exist in Illuminate\View\View, but not in Illuminate\Contracts\View\Factory.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
56
            'append' => $this->append,
57
            'rows'   => $this->rows
58
        ]);
59
    }
60
61
    /**
62
     * @param string $wrap
63
     */
64
    protected function addPickBtn($btn)
65
    {
66
        $style = <<<STYLE
67
.textarea-picker {
68
    padding: 5px;
69
    border-bottom: 1px solid #d2d6de;
70
    border-left: 1px solid #d2d6de;
71
    border-right: 1px solid #d2d6de;
72
    border-bottom-left-radius: 5px;
73
    border-bottom-right-radius: 5px;
74
    background-color: #f1f2f3;
75
}
76
77
.textarea-picker .btn {
78
    padding: 5px 10px;
79
    font-size: 12px;
80
    line-height: 1.5;
81
}
82
STYLE;
83
        Admin::style($style);
84
85
        $this->append = <<<HTML
86
<div class="text-right textarea-picker">
87
    {$btn}
88
</div>
89
HTML;
90
        return $this;
91
    }
92
}
93