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:12
created

ArgumentsResolver::resolve()   C

Complexity

Conditions 7
Paths 7

Size

Total Lines 32
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 7.0099

Importance

Changes 0
Metric Value
dl 0
loc 32
ccs 16
cts 17
cp 0.9412
rs 6.7272
c 0
b 0
f 0
cc 7
eloc 17
nc 7
nop 2
crap 7.0099
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();
1 ignored issue
show
Bug introduced by
Consider using $element->name. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
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
            $params[$parameter->getName()] = $arguments[$parameter->getName()];
1 ignored issue
show
Bug introduced by
Consider using $parameter->name. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
77
        }
78
79 1
        return $params;
80
    }
81
}
82