VariadicArgumentOrganiser   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 29
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A organiseArguments() 0 10 2
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