Completed
Push — master ( 463d73...47ba96 )
by Gerrit
02:04
created

ArgumentCall::resolve()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 9
cts 9
cp 1
rs 9.6666
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
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\Argument;
16
use Closure;
17
use Webmozart\Assert\Assert;
18
19
final class ArgumentCall implements Argument
20
{
21
22
    /**
23
     * @var Argument
24
     */
25
    private $callee;
26
27
    /**
28
     * @var string
29
     */
30
    private $methodName;
31
32
    /**
33
     * @var array<Argument>
34
     */
35
    private $arguments = array();
36
37 1
    public function __construct(
38
        Argument $callee,
39
        string $methodName,
40
        array $arguments
41
    ) {
42 1
        $this->callee = $callee;
43 1
        $this->methodName = $methodName;
44
        $this->arguments = array_map(function (Argument $argument): Argument {
45 1
            return $argument;
46 1
        }, $arguments);
47 1
    }
48
49 1
    public function resolve()
50
    {
51
        /** @var Closure $callee */
52 1
        $callee = $this->callee->resolve();
53 1
        Assert::object($callee);
54 1
        Assert::methodExists($callee, $this->methodName);
55
56
        /** @var array<mixed> $arguments */
57 1
        $arguments = array_map(
58
            /** @return mixed */
59
            function (Argument $argument) {
60 1
                return $argument->resolve();
61 1
            },
62 1
            $this->arguments
63
        );
64
65 1
        return call_user_func_array([$callee, $this->methodName], $arguments);
66
    }
67
68
}
69