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

getStepArgumentValueFor()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 9
c 0
b 0
f 0
rs 9.6666
ccs 0
cts 5
cp 0
cc 2
eloc 5
nc 2
nop 1
crap 6
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\Context\Initializer;
13
14
use Behat\Behat\Context\Context;
15
use Behat\Behat\Context\Initializer\ContextInitializer;
16
use Behat\Behat\EventDispatcher\Event\ScenarioTested;
17
use Gorghoa\ScenarioStateBehatExtension\Annotation\ScenarioStateArgument;
18
use Gorghoa\ScenarioStateBehatExtension\Context\ScenarioStateAwareContext;
19
use Gorghoa\ScenarioStateBehatExtension\ScenarioState;
20
use Gorghoa\ScenarioStateBehatExtension\ScenarioStateInterface;
21
use Gorghoa\StepArgumentInjectorBehatExtension\Annotation\StepInjectorArgument;
22
use Gorghoa\StepArgumentInjectorBehatExtension\Argument\StepArgumentHolder;
23
use Gorghoa\StepArgumentInjectorBehatExtension\Exception\RejectedAnnotationException;
24
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
25
26
/**
27
 * @author Rodrigue Villetard <[email protected]>
28
 */
29
class ScenarioStateInitializer implements ContextInitializer, EventSubscriberInterface, StepArgumentHolder
30
{
31
    /**
32
     * @var ScenarioStateInterface
33
     */
34
    private $store;
35
36 2
    public function __construct()
37
    {
38 2
        $this->clearStore();
39 2
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44 1
    public static function getSubscribedEvents()
45
    {
46
        return [
47 1
            ScenarioTested::AFTER => ['clearStore'],
48
        ];
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54 1
    public function initializeContext(Context $context)
55
    {
56 1
        if (!$context instanceof ScenarioStateAwareContext) {
57
            return;
58
        }
59
60 1
        $context->setScenarioState($this->store);
61 1
    }
62
63 2
    public function clearStore()
64
    {
65 2
        $this->store = new ScenarioState();
66 2
    }
67
68
    /**
69
     * @return ScenarioStateInterface
70
     */
71 2
    public function getStore()
72
    {
73 2
        return $this->store;
74
    }
75
76
    /**
77
     * Test if this service should handle specific argument injection.
78
     *
79
     * @param StepInjectorArgument $annotation
80
     *
81
     * @return bool
82
     */
83
    public function doesHandleStepArgument(StepInjectorArgument $annotation)
84
    {
85
        return $annotation instanceof ScenarioStateArgument && $this->store->hasStateFragment($annotation->getName());
86
    }
87
88
    /**
89
     * Get an argument value to inject.
90
     *
91
     * @param StepInjectorArgument $annotation
92
     *
93
     * @throws RejectedAnnotationException
94
     *
95
     * @return mixed
96
     */
97
    public function getStepArgumentValueFor(StepInjectorArgument $annotation)
98
    {
99
        if (!($annotation instanceof ScenarioStateArgument)) {
100
            $class = get_class($annotation);
101
            throw new RejectedAnnotationException("$class not handled by ScenarioStateBehatExtension");
102
        }
103
104
        return $this->store->getStateFragment($annotation->getName());
105
    }
106
}
107