Completed
Push — master ( ca14f0...c2f74e )
by Song
02:26
created

HasQuickCreate::renderQuickCreate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Encore\Admin\Grid\Concerns;
4
5
use Encore\Admin\Grid\Tools\QuickCreate;
6
7
trait HasQuickCreate
8
{
9
    protected $hasQuickCreate = false;
10
11
    /**
12
     * @var QuickCreate
13
     */
14
    protected $quickCreate;
15
16
    /**
17
     * @param \Closure $closure
18
     *
19
     * @return $this
20
     */
21
    public function quickCreate(\Closure $closure)
22
    {
23
        $this->quickCreate = new QuickCreate($this);
24
25
        call_user_func($closure, $this->quickCreate);
26
27
        return $this;
28
    }
29
30
    /**
31
     * Indicates grid has quick-create.
32
     *
33
     * @return bool
34
     */
35
    public function hasQuickCreate()
36
    {
37
        return !is_null($this->quickCreate);
38
    }
39
40
    /**
41
     * Render quick-create form.
42
     *
43
     * @return array|string
44
     */
45
    public function renderQuickCreate()
46
    {
47
        $columnCount = $this->visibleColumns()->count();
0 ignored issues
show
Bug introduced by
It seems like visibleColumns() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
48
49
        return $this->quickCreate->render($columnCount);
50
    }
51
}