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.
Completed
Push — master ( d30b96...ac351b )
by Rodrigue
04:22
created

organiseArguments()   B

Complexity

Conditions 5
Paths 3

Size

Total Lines 23
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 1 Features 1
Metric Value
c 3
b 1
f 1
dl 0
loc 23
rs 8.5906
cc 5
eloc 14
nc 3
nop 2
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;
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
    private $baseOrganiser;
27
    private $store;
28
    private $reader;
29
30
    public function __construct(ArgumentOrganiser $organiser, ScenarioStateInitializer $store, Reader $reader)
31
    {
32
        $this->baseOrganiser = $organiser;
33
        $this->store = $store;
34
        $this->reader = $reader;
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    public function organiseArguments(ReflectionFunctionAbstract $function, array $match)
41
    {
42
        $i = array_slice(array_keys($match), -1, 1)[0];
43
        $paramsKeys = array_map(function ($element) {
44
            return $element->name;
45
        }, $function->getParameters());
46
47
        $store = $this->store->getStore();
48
49
        /** @var ScenarioStateArgument[] $annotations */
50
        $annotations = $this->reader->getMethodAnnotations($function);
0 ignored issues
show
Compatibility introduced by
$function of type object<ReflectionFunctionAbstract> is not a sub-type of object<ReflectionMethod>. It seems like you assume a child class of the class ReflectionFunctionAbstract to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
51
        foreach ($annotations as $annotation) {
52
            if ($annotation instanceof ScenarioStateArgument &&
53
                in_array($annotation->getArgument(), $paramsKeys) &&
54
                $store->hasStateFragment($annotation->getName())
55
            ) {
56
                $match[$annotation->getArgument()] = $store->getStateFragment($annotation->getName());
57
                $match[strval(++$i)] = $store->getStateFragment($annotation->getName());
58
            }
59
        }
60
61
        return $this->baseOrganiser->organiseArguments($function, $match);
62
    }
63
}
64