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   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 95.24%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 4
dl 0
loc 61
ccs 20
cts 21
cp 0.9524
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
C resolve() 0 32 7
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