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

ArgumentCall   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 2
dl 0
loc 49
ccs 0
cts 14
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 1
A getValue() 0 17 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\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