CheckboxColumn::getLabel()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Itstructure\GridView\Columns;
4
5
use Itstructure\GridView\Filters\StubFilter;
6
use Itstructure\GridView\Traits\Configurable;
7
8
/**
9
 * Class CheckboxColumn.
10
 * @package Itstructure\GridView\Columns
11
 */
12
class CheckboxColumn extends BaseColumn
13
{
14
    use Configurable;
15
16
    /**
17
     * @var string
18
     */
19
    protected $field;
20
21
    /**
22
     * @var bool|callable
23
     */
24
    protected $display = true;
25
26
    /**
27
     * ActionColumn constructor.
28
     * @param array $config
29
     */
30
    public function __construct(array $config)
31
    {
32
        $this->loadConfig($config);
33
34
        $this->filter = new StubFilter();
35
    }
36
37
    /**
38
     * @return string
39
     */
40
    public function getLabel(): string
41
    {
42
        return $this->label ?? trans('grid_view::grid.deletion');
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->label ?? t...d_view::grid.deletion') could return the type array which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
43
    }
44
45
    /**
46
     * @param $row
47
     * @return mixed
48
     */
49
    public function getValue($row)
50
    {
51
        return $row->{$this->attribute} ?? '';
52
    }
53
54
    /**
55
     * @param $row
56
     * @return array|string
57
     */
58
    public function render($row)
59
    {
60
        if ($this->display === false) {
61
            return view('grid_view::columns.checkbox-stub')->render();
62
        }
63
64
        if (is_callable($this->display) && !call_user_func($this->display, $row)) {
0 ignored issues
show
Bug introduced by
It seems like $this->display can also be of type true; however, parameter $callback of call_user_func() does only seem to accept callable, maybe add an additional type check? ( Ignorable by Annotation )

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

64
        if (is_callable($this->display) && !call_user_func(/** @scrutinizer ignore-type */ $this->display, $row)) {
Loading history...
65
            return view('grid_view::columns.checkbox-stub')->render();
66
        }
67
68
        return view('grid_view::columns.checkbox', [
69
            'field' => $this->field,
70
            'value' => $this->getValue($row),
71
        ])->render();
72
    }
73
}
74