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

ScenarioStateHookDispatcher   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 91
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 11

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 12
lcom 1
cbo 11
dl 0
loc 91
ccs 0
cts 30
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
C dispatchScopeHooks() 0 45 11
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\Hook\Dispatcher;
13
14
use Behat\Testwork\Call\CallCenter;
15
use Behat\Testwork\Call\CallResults;
16
use Behat\Testwork\Environment\Call\EnvironmentCall;
17
use Behat\Testwork\Hook\Call\HookCall;
18
use Behat\Testwork\Hook\HookRepository;
19
use Behat\Testwork\Hook\Scope\HookScope;
20
use Doctrine\Common\Annotations\Reader;
21
use Gorghoa\ScenarioStateBehatExtension\Annotation\ScenarioStateArgument;
22
use Gorghoa\ScenarioStateBehatExtension\Context\Initializer\ScenarioStateInitializer;
23
24
/**
25
 * @author Vincent Chalamon <[email protected]>
26
 */
27
class ScenarioStateHookDispatcher
28
{
29
    /**
30
     * @var HookRepository
31
     */
32
    private $repository;
33
34
    /**
35
     * @var CallCenter
36
     */
37
    private $callCenter;
38
39
    /**
40
     * @var Reader
41
     */
42
    private $reader;
43
44
    /**
45
     * @var ScenarioStateInitializer
46
     */
47
    private $store;
48
49
    /**
50
     * Initializes scenario state hook dispatcher.
51
     *
52
     * @param HookRepository           $repository
53
     * @param CallCenter               $callCenter
54
     * @param ScenarioStateInitializer $store
55
     * @param Reader                   $reader
56
     */
57
    public function __construct(HookRepository $repository, CallCenter $callCenter, ScenarioStateInitializer $store, Reader $reader)
58
    {
59
        $this->repository = $repository;
60
        $this->callCenter = $callCenter;
61
        $this->reader = $reader;
62
        $this->store = $store;
63
    }
64
65
    /**
66
     * Dispatches hooks for a specified event.
67
     *
68
     * @param HookScope $scope
69
     *
70
     * @return CallResults
71
     */
72
    public function dispatchScopeHooks(HookScope $scope)
73
    {
74
        $results = array();
75
        foreach ($this->repository->getScopeHooks($scope) as $hook) {
76
            /** @var \ReflectionMethod $function */
77
            $function = $hook->getReflection();
78
79
            // No `@ScenarioStateArgument` annotation found
80
            if (null === $this->reader->getMethodAnnotation($function, ScenarioStateArgument::class)) {
81
                $results[] = $this->callCenter->makeCall(new HookCall($scope, $hook));
82
                continue;
83
            }
84
85
            $paramsKeys = array_map(function ($element) {
86
                return $element->name;
87
            }, $function->getParameters());
88
            $store = $this->store->getStore();
89
            $params = $arguments = [];
90
91
            // Prepare arguments from annotations
92
            /** @var ScenarioStateArgument[] $annotations */
93
            $annotations = $this->reader->getMethodAnnotations($function);
94
            foreach ($annotations as $annotation) {
95
                if ($annotation instanceof ScenarioStateArgument &&
96
                    in_array($annotation->getArgument(), $paramsKeys) &&
97
                    $store->hasStateFragment($annotation->getName())
98
                ) {
99
                    $params[$annotation->getArgument()] = $store->getStateFragment($annotation->getName());
100
                }
101
            }
102
103
            // Manage `scope` argument
104
            foreach ($function->getParameters() as $parameter) {
105
                if (null !== $parameter->getClass() && get_class($scope) === $parameter->getClass()->getName()) {
0 ignored issues
show
Bug introduced by
Consider using $parameter->getClass()->name. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
106
                    $arguments[$parameter->getName()] = $scope;
0 ignored issues
show
Bug introduced by
Consider using $parameter->name. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
107
                } elseif (isset($params[$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...
108
                    $arguments[$parameter->getName()] = $params[$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...
109
                }
110
            }
111
112
            $results[] = $this->callCenter->makeCall(new EnvironmentCall($scope->getEnvironment(), $hook, $arguments));
113
        }
114
115
        return new CallResults($results);
116
    }
117
}
118