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 (#31)
by Rodrigue
01:55
created

ArgumentOrganiser::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 4
nc 1
nop 3
1
<?php
2
3
/*
4
 * This file is part of the StepArgumentInjectorBehatExtension 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\StepArgumentInjectorBehatExtension\Argument;
13
14
use Behat\Testwork\Argument\ArgumentOrganiser as BehatArgumentOrganiser;
15
use Doctrine\Common\Annotations\Reader;
16
use Gorghoa\StepArgumentInjectorBehatExtension\Annotation\StepArgumentInjectorArgument;
17
use Gorghoa\StepArgumentInjectorBehatExtension\Annotation\StepInjectorArgument;
18
// use Gorghoa\StepArgumentInjectorBehatExtension\Context\Initializer\StepArgumentInjectorInitializer;
19
use ReflectionFunctionAbstract;
20
21
/**
22
 * @author Rodrigue Villetard <[email protected]>
23
 * @author Vincent Chalamon <[email protected]>
24
 */
25
final class ArgumentOrganiser implements BehatArgumentOrganiser
26
{
27
    /**
28
     * @var BehatArgumentOrganiser
29
     */
30
    private $baseOrganiser;
31
32
    /**
33
     * @var StepArgumentInjectorInitializer
34
     */
35
    private $hookers;
36
37
    /**
38
     * @var Reader
39
     */
40
    private $reader;
41
42
    public function __construct(BehatArgumentOrganiser $organiser, array $hookers, Reader $reader)
43
    {
44
        $this->baseOrganiser = $organiser;
45
        $this->hookers = $hookers;
0 ignored issues
show
Documentation Bug introduced by
It seems like $hookers of type array is incompatible with the declared type object<Gorghoa\StepArgum...entInjectorInitializer> of property $hookers.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
46
        $this->reader = $reader;
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52
    public function organiseArguments(ReflectionFunctionAbstract $function, array $match)
53
    {
54
        $i = array_slice(array_keys($match), -1, 1)[0];
55
        $paramsKeys = array_map(function ($element) {
56
            return $element->name;
57
        }, $function->getParameters());
58
59
        if (!$function instanceof \ReflectionMethod) {
60
            return $this->baseOrganiser->organiseArguments($function, $match);
61
        }
62
63
        /** @var StepArgumentInjectorArgument[] $annotations */
64
        $annotations = $this->reader->getMethodAnnotations($function);
65
66 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
            if ($annotation instanceof StepInjectorArgument &&
68
                in_array($annotation->getArgument(), $paramsKeys)
69
            ) {
70
                foreach ($this->hookers as $hooker) {
71
                    if ($hooker->hasStepArgumentFor($annotation->getName())) {
72
                        $match[$annotation->getArgument()]
73
                            = $match[strval(++$i)]
74
                            = $hooker->getStepArgumentFor($annotation->getName())
75
                        ;
76
                    }
77
                }
78
            }
79
        }
80
81
        return $this->baseOrganiser->organiseArguments($function, $match);
82
    }
83
}
84