Test Setup Failed
Push — master ( 8eb8d2...671183 )
by Churakov
04:26 queued 12s
created

BaseColumn::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
rs 10
c 1
b 0
f 1
1
<?php
2
3
namespace ChurakovMike\EasyGrid\Columns;
4
5
use ChurakovMike\EasyGrid\Filters\BaseFilter;
6
use ChurakovMike\EasyGrid\Filters\TextFilter;
7
use ChurakovMike\EasyGrid\Traits\Configurable;
8
9
/**
10
 * Class BaseColumn.
11
 * @package ChurakovMike\EasyGrid\Columns
12
 *
13
 * @property string $label
14
 * @property string $attribute
15
 * @property string|\Closure|mixed $value
16
 * @property BaseFilter $filter
17
 */
18
abstract class BaseColumn
19
{
20
    use Configurable;
21
22
    /**
23
     * @var string $label
24
     */
25
    public $label;
26
27
    /**
28
     * @var string $attribute
29
     */
30
    public $attribute;
31
32
    /**
33
     * @var string $value
34
     */
35
    public $value;
36
37
    /**
38
     * @var string $filter
39
     */
40
    public $filter;
41
42
    /**
43
     * BaseColumn constructor.
44
     * @param array $config
45
     */
46
    public function __construct(array $config)
47
    {
48
        $this->loadConfig($config);
49
50
        $this->buildFilter();
51
    }
52
53
    /**
54
     * @param $row
55
     * @return string
56
     */
57
    public function getValue($row): string
0 ignored issues
show
Unused Code introduced by
The parameter $row is not used and could be removed. ( Ignorable by Annotation )

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

57
    public function getValue(/** @scrutinizer ignore-unused */ $row): string

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
58
    {
59
    }
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return string. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
60
61
    /**
62
     * Get title for grid head.
63
     *
64
     * @return string
65
     */
66
    public function getLabel(): string
67
    {
68
        return $this->label ?? ucfirst($this->attribute);
69
    }
70
71
    /**
72
     * Get attribute.
73
     *
74
     * @return string
75
     */
76
    public function getAttribute(): string
77
    {
78
        return $this->attribute;
79
    }
80
81
    /**
82
     * Build filter for grid.
83
     *
84
     * @return void
85
     */
86
    protected function buildFilter()
87
    {
88
        if (is_null($this->filter)) {
89
            $this->filter = new TextFilter([
90
                'name' => $this->getAttribute(),
91
            ]);
92
        }
93
    }
94
}
95