Test Failed
Push — master ( 794710...4acb1e )
by Georgi
03:38
created

ActionBarItem::addCallback()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 4
nop 0
dl 0
loc 11
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Epesi\Core\Layout\View;
4
5
use atk4\ui\Item;
6
use atk4\ui\jsCallback;
7
8
class ActionBarItem extends Item
9
{
10
    public $weight = 10;
11
    
12
    public $callback;
13
    
14
    public $hint;
15
    
16
    public function renderView()
17
    {
18
        $this->addCallback();
19
        
20
        if ($this->hint) {
21
            $this->attr['title'] = $this->hint;
22
        }
23
        
24
        parent::renderView();
25
    }
26
    
27
    public function callback($callable)
28
    {
29
        $this->callback = $callable;
30
        
31
        return $this;
32
    }
33
    
34
    public function addCallback()
35
    {
36
        if (is_callable($callable = $this->callback)) {
37
            $callable = $this->add('jsCallback')->set($callable);
38
        }
39
        
40
        if ($callable instanceof jsCallback) {
41
            $this->on('click', $callable);
0 ignored issues
show
Bug introduced by
$callable of type atk4\ui\jsCallback is incompatible with the type string expected by parameter $selector of atk4\ui\View::on(). ( Ignorable by Annotation )

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

41
            $this->on('click', /** @scrutinizer ignore-type */ $callable);
Loading history...
42
        }
43
        
44
        return $this;
45
    }
46
}
47