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 (#24)
by Vincent
02:57
created

ScenarioStateArgumentOrganiser::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 3
crap 1
1
<?php
2
3
/*
4
 * This file is part of the ScenarioStateBehatExtension 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\ScenarioStateBehatExtension\Argument;
13
14
use Behat\Testwork\Argument\ArgumentOrganiser;
15
use Doctrine\Common\Annotations\Reader;
16
use Gorghoa\ScenarioStateBehatExtension\Annotation\ScenarioStateArgument;
17
use Gorghoa\ScenarioStateBehatExtension\Context\Initializer\ScenarioStateInitializer;
18
use ReflectionFunctionAbstract;
19
20
/**
21
 * @author Rodrigue Villetard <[email protected]>
22
 * @author Vincent Chalamon <[email protected]>
23
 */
24
final class ScenarioStateArgumentOrganiser implements ArgumentOrganiser
25
{
26
    /**
27
     * @var ArgumentOrganiser
28
     */
29
    private $baseOrganiser;
30
31
    /**
32
     * @var ScenarioStateInitializer
33
     */
34
    private $store;
35
36
    /**
37
     * @var Reader
38
     */
39
    private $reader;
40
41 1
    public function __construct(ArgumentOrganiser $organiser, ScenarioStateInitializer $store, Reader $reader)
42
    {
43 1
        $this->baseOrganiser = $organiser;
44 1
        $this->store = $store;
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
        $store = $this->store->getStore();
59
60 1
        if (!($function instanceof \ReflectionMethod)) {
61
            return $this->baseOrganiser->organiseArguments($function, $match);
62
        }
63
64
        /** @var ScenarioStateArgument[] $annotations */
65 1
        $annotations = $this->reader->getMethodAnnotations($function);
66 1 View Code Duplication
        foreach ($annotations as $annotation) {
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...
67 1
            if ($annotation instanceof ScenarioStateArgument &&
68 1
                in_array($annotation->getArgument(), $paramsKeys) &&
69 1
                $store->hasStateFragment($annotation->getName())
70
            ) {
71 1
                $match[$annotation->getArgument()] = $store->getStateFragment($annotation->getName());
72 1
                $match[strval(++$i)] = $store->getStateFragment($annotation->getName());
73
            }
74
        }
75
76 1
        return $this->baseOrganiser->organiseArguments($function, $match);
77
    }
78
}
79