Call::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace Bdf\Collection\Util\Functor\Consumer;
4
5
/**
6
 * Consumer for call a method of the input element
7
 *
8
 * <code>
9
 * $entities->forEach(new Call('update', [['enabled']]);
10
 * </code>
11
 */
12
final class Call implements ConsumerInterface
13
{
14
    /**
15
     * @var string
16
     */
17
    private $method;
18
19
    /**
20
     * @var array
21
     */
22
    private $arguments;
23
24
25
    /**
26
     * Call constructor.
27
     *
28
     * @param string $method
29
     * @param array $arguments
30
     */
31 1
    public function __construct(string $method, array $arguments = [])
32
    {
33 1
        $this->method = $method;
34 1
        $this->arguments = $arguments;
35 1
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40 1
    public function __invoke($element, $key = null): void
41
    {
42 1
        $element->{$this->method}(...$this->arguments);
43 1
    }
44
}
45