Passed
Push — master ( 493c3e...a4042e )
by Thomas
03:08
created

GenericTabulatorTool   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 93
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 11
eloc 30
c 1
b 0
f 1
dl 0
loc 93
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A getIcon() 0 3 1
A getCallable() 0 3 1
A setButtonType() 0 4 1
A __construct() 0 8 1
A getButtonType() 0 3 1
A index() 0 4 1
A forTemplate() 0 12 3
A setIcon() 0 4 1
A setCallable() 0 4 1
1
<?php
2
3
namespace LeKoala\Tabulator;
4
5
use SilverStripe\View\ArrayData;
6
7
/**
8
 * Generic tool with a callable
9
 */
10
class GenericTabulatorTool extends AbstractTabulatorTool
11
{
12
    protected $callable = null;
13
    protected string $name = '';
14
    protected string $label = '';
15
    protected string $icon = '';
16
    protected string $buttonType = 'secondary';
17
18
    public function __construct($name, $label, $callable = null, $icon = '')
19
    {
20
        parent::__construct();
21
22
        $this->name = $name;
23
        $this->label = $label;
24
        $this->icon = $icon;
25
        $this->callable = $callable;
26
    }
27
28
    public function forTemplate()
29
    {
30
        $fontIcon = '';
31
        if ($this->icon) {
32
            $fontIcon = ' font-icon-' . $this->icon;
33
        }
34
        $data = new ArrayData([
35
            'ButtonName' => $this->label,
36
            'ButtonClasses' => 'btn-' . $this->buttonType . $fontIcon,
37
            'Icon' => $this->isAdmini() ? $this->icon : '',
38
        ]);
39
        return $this->renderWith($this->getViewerTemplates(), $data);
0 ignored issues
show
Bug introduced by
$data of type SilverStripe\View\ArrayData is incompatible with the type array expected by parameter $customFields of SilverStripe\View\ViewableData::renderWith(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

39
        return $this->renderWith($this->getViewerTemplates(), /** @scrutinizer ignore-type */ $data);
Loading history...
40
    }
41
42
    public function index()
43
    {
44
        $callable = $this->callable;
45
        return $callable($this->tabulatorGrid);
46
    }
47
48
    /**
49
     * Get the value of callable
50
     */
51
    public function getCallable()
52
    {
53
        return $this->callable;
54
    }
55
56
    /**
57
     * Set the value of callable
58
     *
59
     * @param callable $callable
60
     */
61
    public function setCallable($callable): self
62
    {
63
        $this->callable = $callable;
64
        return $this;
65
    }
66
67
    /**
68
     * Get the value of icon
69
     */
70
    public function getIcon(): string
71
    {
72
        return $this->icon;
73
    }
74
75
    /**
76
     * Set the value of icon
77
     *
78
     * @param string $icon
79
     */
80
    public function setIcon($icon): self
81
    {
82
        $this->icon = $icon;
83
        return $this;
84
    }
85
86
    /**
87
     * Get the value of buttonType
88
     */
89
    public function getButtonType(): string
90
    {
91
        return $this->buttonType;
92
    }
93
94
    /**
95
     * Set the value of buttonType
96
     *
97
     * @param string $buttonType
98
     */
99
    public function setButtonType($buttonType): self
100
    {
101
        $this->buttonType = $buttonType;
102
        return $this;
103
    }
104
}
105