Custom::getValue()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 10
ccs 0
cts 8
cp 0
rs 9.4285
cc 2
eloc 5
nc 2
nop 0
crap 6
1
<?php
2
3
namespace Sco\Admin\Display\Columns;
4
5
class Custom extends Column
6
{
7
    protected $type = 'custom';
8
9
    protected $callback;
10
11
    public function __construct($name, $label, \Closure $callback = null)
12
    {
13
        parent::__construct($name, $label);
14
        $this->setCallback($callback);
15
    }
16
17
    /**
18
     * @return mixed
19
     */
20
    public function getCallback()
21
    {
22
        return $this->callback;
23
    }
24
25
    /**
26
     * @param $callback
27
     *
28
     * @return $this
29
     */
30
    public function setCallback($callback)
31
    {
32
        $this->callback = $callback;
33
34
        return $this;
35
    }
36
37
    public function getValue()
38
    {
39
        $callback = $this->getCallback();
40
41
        if (! is_callable($callback)) {
42
            throw new \InvalidArgumentException('Invalid custom column callback');
43
        }
44
45
        return call_user_func($callback, $this->getModel());
46
    }
47
}
48