Completed
Push — master ( 677e94...463d73 )
by Gerrit
02:18
created

ArgumentCall::getValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 17
ccs 0
cts 8
cp 0
rs 9.7
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
/**
3
 * Copyright (C) 2018 Gerrit Addiks.
4
 * This package (including this file) was released under the terms of the GPL-3.0.
5
 * You should have received a copy of the GNU General Public License along with this program.
6
 * If not, see <http://www.gnu.org/licenses/> or send me a mail so i can send you a copy.
7
 *
8
 * @license GPL-3.0
9
 *
10
 * @author Gerrit Addiks <[email protected]>
11
 */
12
13
namespace Addiks\SymfonyGenerics\Arguments;
14
15
use Addiks\SymfonyGenerics\Arguments\ArgumentInterface;
16
use Closure;
17
use Webmozart\Assert\Assert;
18
19
final class ArgumentCall implements ArgumentInterface
20
{
21
22
    /**
23
     * @var ArgumentInterface
24
     */
25
    private $callee;
26
27
    /**
28
     * @var string
29
     */
30
    private $methodName;
31
32
    /**
33
     * @var array<ArgumentInterface>
34
     */
35
    private $arguments = array();
36
37
    public function __construct(
38
        ArgumentInterface $callee,
39
        string $methodName,
40
        array $arguments
41
    ) {
42
        $this->callee = $callee;
43
        $this->methodName = $methodName;
44
        $this->arguments = array_map(function (ArgumentInterface $argument): ArgumentInterface {
45
            return $argument;
46
        }, $arguments);
47
    }
48
49
    public function getValue()
50
    {
51
        /** @var Closure $callee */
52
        $callee = $this->callee->getValue();
53
        Assert::isCallable($callee);
54
55
        /** @var array<mixed> $arguments */
56
        $arguments = array_map(
57
            /** @return mixed */
58
            function (ArgumentInterface $argument) {
59
                return $argument->getValue();
60
            },
61
            $this->arguments
62
        );
63
64
        return call_user_func([$callee, $this->methodName], $arguments);
65
    }
66
67
}
68