GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Pull Request — master (#31)
by Rodrigue
01:53
created

ArgumentOrganiser::organiseArguments()   C

Complexity

Conditions 7
Paths 6

Size

Total Lines 32
Code Lines 17

Duplication

Lines 14
Ratio 43.75 %

Code Coverage

Tests 16
CRAP Score 7.0099

Importance

Changes 0
Metric Value
dl 14
loc 32
ccs 16
cts 17
cp 0.9412
rs 6.7272
c 0
b 0
f 0
cc 7
eloc 17
nc 6
nop 2
crap 7.0099
1
<?php
2
3
/*
4
 * This file is part of the StepArgumentInjectorBehatExtension project.
5
 *
6
 * (c) Rodrigue Villetard <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Gorghoa\StepArgumentInjectorBehatExtension\Argument;
13
14
use Behat\Testwork\Argument\ArgumentOrganiser as BehatArgumentOrganiser;
15
use Doctrine\Common\Annotations\Reader;
16
use Gorghoa\StepArgumentInjectorBehatExtension\Annotation\StepInjectorArgument;
17
// use Gorghoa\StepArgumentInjectorBehatExtension\Context\Initializer\StepArgumentInjectorInitializer;
18
use ReflectionFunctionAbstract;
19
20
/**
21
 * @author Rodrigue Villetard <[email protected]>
22
 * @author Vincent Chalamon <[email protected]>
23
 */
24
final class ArgumentOrganiser implements BehatArgumentOrganiser
25
{
26
    /**
27
     * @var BehatArgumentOrganiser
28
     */
29
    private $baseOrganiser;
30
31
    /**
32
     * @var StepArgumentHolder[]
33
     */
34
    private $stepArgumentHolders;
35
36
    /**
37
     * @var Reader
38
     */
39
    private $reader;
40
41 1
    public function __construct(BehatArgumentOrganiser $organiser, array $stepArgumentHolders, Reader $reader)
42
    {
43 1
        $this->baseOrganiser = $organiser;
44 1
        $this->stepArgumentHolders = $stepArgumentHolders;
45 1
        $this->reader = $reader;
46 1
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51 1
    public function organiseArguments(ReflectionFunctionAbstract $function, array $match)
52
    {
53 1
        $i = array_slice(array_keys($match), -1, 1)[0];
54 1
        $paramsKeys = array_map(function ($element) {
55 1
            return $element->name;
56 1
        }, $function->getParameters());
57
58 1
        if (!$function instanceof \ReflectionMethod) {
59
            return $this->baseOrganiser->organiseArguments($function, $match);
60
        }
61
62 1
        $annotations = $this->reader->getMethodAnnotations($function);
63
64 1
        foreach ($annotations as $annotation) {
65 1 View Code Duplication
            if ($annotation instanceof StepInjectorArgument &&
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
66 1
                in_array($argument = $annotation->getArgument(), $paramsKeys)
67
            ) {
68
                /* @var StepInjectorArgument $annotation */
69 1
                foreach ($this->stepArgumentHolders as $hooker) {
70 1
                    if ($hooker->doesHandleStepArgument($annotation)) {
71
72 1
                        $match[$argument]
73 1
                            = $match[strval(++$i)]
74 1
                            = $hooker->getStepArgumentValueFor($annotation)
75
                        ;
76
                    }
77
                }
78
            }
79
        }
80
81 1
        return $this->baseOrganiser->organiseArguments($function, $match);
82
    }
83
}
84