ClosureRenderer::setRequiredColumns()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
/*
5
 * soluble-flexstore library
6
 *
7
 * @author    Vanvelthem Sébastien
8
 * @link      https://github.com/belgattitude/soluble-flexstore
9
 * @copyright Copyright (c) 2016-2017 Vanvelthem Sébastien
10
 * @license   MIT License https://github.com/belgattitude/soluble-flexstore/blob/master/LICENSE.md
11
 *
12
 */
13
14
namespace Soluble\FlexStore\Renderer;
15
16
use ArrayObject;
17
use Closure;
18
19
/**
20
 * @method void closure(ArrayObject $row)
21
 */
22
class ClosureRenderer implements RowRendererInterface
23
{
24
    /**
25
     * @var Closure
26
     */
27
    protected $closure;
28
29
    /**
30
     * @var array
31
     */
32
    protected $required_columns;
33
34
    /**
35
     * @param Closure $closure
36
     */
37 6
    public function __construct(Closure $closure)
38
    {
39 6
        $this->required_columns = [];
40 6
        $this->closure = $closure;
41 6
    }
42
43
    /**
44
     * Magic callable.
45
     *
46
     * @param string $method
47
     * @param array  $args
48
     */
49 5
    public function __call($method, $args)
50
    {
51 5
        if (is_callable([$this, $method])) {
52 5
            return call_user_func_array($this->$method, $args);
53
        }
54
    }
55
56 5
    public function apply(\ArrayObject $row): void
57
    {
58 5
        $this->closure($row);
59 4
    }
60
61
    /**
62
     * Return the list of columns required in order to use this renderer.
63
     *
64
     * @return array
65
     */
66 6
    public function getRequiredColumns(): array
67
    {
68 6
        return $this->required_columns;
69
    }
70
71
    /**
72
     * @param array $required_columns
73
     */
74 2
    public function setRequiredColumns(array $required_columns)
75
    {
76 2
        $this->required_columns = $required_columns;
77 2
    }
78
}
79