VariadicArgumentOrganiser::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the VariadicExtension package.
7
 *
8
 * (c) Kamil Kokot <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace FriendsOfBehat\VariadicExtension\Argument;
15
16
use Behat\Testwork\Argument\ArgumentOrganiser;
17
use ReflectionFunctionAbstract;
18
19
/**
20
 * Decorates a default argument organiser to support a variadic arguments also.
21
 * It will add all unused arguments to the end of argument list.
22
 */
23
final class VariadicArgumentOrganiser implements ArgumentOrganiser
24
{
25
    /**
26
     * @var ArgumentOrganiser
27
     */
28
    private $decoratedArgumentOrganiser;
29
30
    /**
31
     * @param ArgumentOrganiser $decoratedArgumentOrganiser
32
     */
33
    public function __construct(ArgumentOrganiser $decoratedArgumentOrganiser)
34
    {
35
        $this->decoratedArgumentOrganiser = $decoratedArgumentOrganiser;
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function organiseArguments(ReflectionFunctionAbstract $function, array $arguments): array
42
    {
43
        $organisedArguments = $this->decoratedArgumentOrganiser->organiseArguments($function, $arguments);
44
45
        if ($function->isVariadic()) {
46
            $organisedArguments += array_diff($arguments, $organisedArguments);
47
        }
48
49
        return $organisedArguments;
50
    }
51
}
52