Func::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 3
c 0
b 0
f 0
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 10
cc 1
nc 1
nop 3
crap 1
1
<?php
2
3
namespace kalanis\kw_table\core\Table\Columns;
4
5
6
use kalanis\kw_connect\core\Interfaces\IRow;
7
8
9
/**
10
 * Class Func
11
 * @package kalanis\kw_table\core\Table\Columns
12
 * Each row in Column will pass through external function
13
 */
14
class Func extends AColumn
15
{
16
    /** @var callable */
17
    protected $callback;
18
    /** @var array<int, float|int|string|bool|null> */
19
    protected array $param;
20
21
    /**
22
     * @param string $sourceName
23
     * @param callable $callback
24
     * @param array<int, float|int|string|bool|null> $param+
25
     */
26 1
    public function __construct(string $sourceName, $callback, array $param = [])
27
    {
28 1
        $this->sourceName = $sourceName;
29 1
        $this->callback = $callback;
30 1
        $this->param = $param;
31 1
    }
32
33 1
    public function getValue(IRow $source)
34
    {
35 1
        $param = array_merge([parent::getValue($source)], $this->param);
36 1
        return call_user_func_array($this->callback, $param);
37
    }
38
}
39