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

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

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::fieldRender([
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (fieldRender() instead of render()). Are you sure this is correct? If so, you might want to change this to $this->fieldRender().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

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