Completed
Push — master ( 69a7c6...5199b6 )
by Song
02:55
created

HasTools::renderHeaderTools()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Encore\Admin\Grid\Concerns;
4
5
use Closure;
6
use Encore\Admin\Grid\Tools;
7
8
trait HasTools
9
{
10
    use HasSearchBar;
11
12
    /**
13
     * Header tools.
14
     *
15
     * @var Tools
16
     */
17
    public $tools;
18
19
    /**
20
     * Setup grid tools.
21
     *
22
     * @return $this
23
     */
24
    protected function initTools()
25
    {
26
        $this->tools = new Tools($this);
27
28
        return $this;
29
    }
30
31
    /**
32
     * Disable header tools.
33
     *
34
     * @return $this
35
     */
36
    public function disableTools(bool $disable = true)
37
    {
38
        return $this->option('show_tools', !$disable);
0 ignored issues
show
Bug introduced by
It seems like option() 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...
39
    }
40
41
    /**
42
     * Setup grid tools.
43
     *
44
     * @param Closure $callback
45
     *
46
     * @return void
47
     */
48
    public function tools(Closure $callback)
49
    {
50
        call_user_func($callback, $this->tools);
51
    }
52
53
    /**
54
     * Render custom tools.
55
     *
56
     * @return string
57
     */
58
    public function renderHeaderTools()
59
    {
60
        return $this->tools->render();
61
    }
62
63
    /**
64
     * If grid show header tools.
65
     *
66
     * @return bool
67
     */
68
    public function showTools()
69
    {
70
        return $this->option('show_tools');
0 ignored issues
show
Bug introduced by
It seems like option() 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...
71
    }
72
}
73