Completed
Push — master ( c6a049...7f7ede )
by Song
03:29
created

HasTools   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setupTools() 0 4 1
A disableTools() 0 4 1
A tools() 0 4 1
A renderHeaderTools() 0 4 1
A showTools() 0 4 1
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
    /**
11
     * Header tools.
12
     *
13
     * @var Tools
14
     */
15
    public $tools;
16
17
    /**
18
     * Setup grid tools.
19
     */
20
    public function setupTools()
21
    {
22
        $this->tools = new Tools($this);
23
    }
24
25
    /**
26
     * Disable header tools.
27
     *
28
     * @return $this
29
     */
30
    public function disableTools(bool $disable = true)
31
    {
32
        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...
33
    }
34
35
    /**
36
     * Setup grid tools.
37
     *
38
     * @param Closure $callback
39
     *
40
     * @return void
41
     */
42
    public function tools(Closure $callback)
43
    {
44
        call_user_func($callback, $this->tools);
45
    }
46
47
    /**
48
     * Render custom tools.
49
     *
50
     * @return string
51
     */
52
    public function renderHeaderTools()
53
    {
54
        return $this->tools->render();
55
    }
56
57
    /**
58
     * If grid show header tools.
59
     *
60
     * @return bool
61
     */
62
    public function showTools()
63
    {
64
        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...
65
    }
66
}