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
02:11
created

ScenarioStateInitializer   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 63.64%

Importance

Changes 0
Metric Value
dl 0
loc 62
c 0
b 0
f 0
wmc 10
lcom 1
cbo 5
rs 10
ccs 14
cts 22
cp 0.6364

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getSubscribedEvents() 0 6 1
A initializeContext() 0 8 2
A clearStore() 0 4 1
A getStore() 0 4 1
A doesHandleStepArgument() 0 4 2
A getStepArgumentValueFor() 0 9 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\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\RejectedAnnotation;
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
    public function doesHandleStepArgument(StepInjectorArgument $annotation)
77
    {
78
        return $annotation instanceof ScenarioStateArgument && $this->store->hasStateFragment($annotation->getName());
79
    }
80
81
    public function getStepArgumentValueFor(StepInjectorArgument $annotation)
82
    {
83
        if (!($annotation instanceof ScenarioStateArgument)) {
84
            $class = get_class($annotation);
85
            throw new RejectedAnnotation("$class not handled by ScenarioStateBehatExtension");
86
        }
87
88
        return $this->store->getStateFragment($annotation->getName());
89
    }
90
}
91