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

ArgumentsResolver::resolve()   C

Complexity

Conditions 8
Paths 10

Size

Total Lines 33
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 8.0109

Importance

Changes 0
Metric Value
dl 0
loc 33
ccs 17
cts 18
cp 0.9444
rs 5.3846
c 0
b 0
f 0
cc 8
eloc 18
nc 10
nop 2
crap 8.0109
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\Resolver;
13
14
use Doctrine\Common\Annotations\Reader;
15
use Gorghoa\ScenarioStateBehatExtension\Annotation\ScenarioStateArgument;
16
use Gorghoa\ScenarioStateBehatExtension\Context\Initializer\ScenarioStateInitializer;
17
18
/**
19
 * @author Vincent Chalamon <[email protected]>
20
 */
21
class ArgumentsResolver
22
{
23
    /**
24
     * @var ScenarioStateInitializer
25
     */
26
    private $store;
27
28
    /**
29
     * @var Reader
30
     */
31
    private $reader;
32
33
    /**
34
     * @param ScenarioStateInitializer $store
35
     * @param Reader                   $reader
36
     */
37 1
    public function __construct(ScenarioStateInitializer $store, Reader $reader)
38
    {
39 1
        $this->store = $store;
40 1
        $this->reader = $reader;
41 1
    }
42
43
    /**
44
     * @param \ReflectionMethod $function
45
     * @param array             $arguments
46
     *
47
     * @return array
48
     */
49 1
    public function resolve(\ReflectionMethod $function, array $arguments)
50
    {
51
        // No `@ScenarioStateArgument` annotation found
52 1
        if (null === $this->reader->getMethodAnnotation($function, ScenarioStateArgument::class)) {
53
            return $arguments;
54
        }
55
56 1
        $paramsKeys = array_map(function (\ReflectionParameter $element) {
57 1
            return $element->getName();
58 1
        }, $function->getParameters());
59 1
        $store = $this->store->getStore();
60
61
        // Prepare arguments from annotations
62
        /** @var ScenarioStateArgument[] $annotations */
63 1
        $annotations = $this->reader->getMethodAnnotations($function);
64 1
        foreach ($annotations as $annotation) {
65 1
            if ($annotation instanceof ScenarioStateArgument &&
66 1
                in_array($annotation->getArgument(), $paramsKeys) &&
67 1
                $store->hasStateFragment($annotation->getName())
68
            ) {
69 1
                $arguments[$annotation->getArgument()] = $store->getStateFragment($annotation->getName());
70
            }
71
        }
72
73
        // Reorder arguments
74 1
        $params = [];
75 1
        foreach ($function->getParameters() as $parameter) {
76 1
            $name = $parameter->getName();
0 ignored issues
show
Bug introduced by
Consider using $parameter->name. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
77 1
            $params[$name] = isset($arguments[$name]) ? $arguments[$name] : $arguments[$parameter->getPosition()];
78
        }
79
80 1
        return $params;
81
    }
82
}
83