Completed
Push — master ( 631589...ae2f10 )
by Song
02:39
created

Textarea   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 83
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A rows() 0 6 1
A render() 0 17 3
A addPickBtn() 0 28 1
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($this);
0 ignored issues
show
Unused Code introduced by
The call to Textarea::mountPicker() has too many arguments starting with $this.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
52
53
        return parent::render()->with([
0 ignored issues
show
Bug introduced by
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...
54
            'append' => $this->append,
55
            'rows'   => $this->rows
56
        ]);
57
    }
58
59
    /**
60
     * @param string $wrap
0 ignored issues
show
Bug introduced by
There is no parameter named $wrap. 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...
61
     */
62
    public function addPickBtn($btn)
63
    {
64
        $style = <<<STYLE
65
.textarea-picker {
66
    padding: 5px;
67
    border-bottom: 1px solid #d2d6de;
68
    border-left: 1px solid #d2d6de;
69
    border-right: 1px solid #d2d6de;
70
    border-bottom-left-radius: 5px;
71
    border-bottom-right-radius: 5px;
72
    background-color: #f1f2f3;
73
}
74
75
.textarea-picker .btn {
76
    padding: 5px 10px;
77
    font-size: 12px;
78
    line-height: 1.5;
79
}
80
STYLE;
81
        Admin::style($style);
82
83
        $this->append = <<<HTML
84
<div class="text-right textarea-picker">
85
    {$btn}
86
</div>
87
HTML;
88
        return $this;
89
    }
90
}
91