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

ScenarioStateExtension::load()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 49
Code Lines 34

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 49
rs 9.2258
c 0
b 0
f 0
cc 1
eloc 34
nc 1
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\ServiceContainer;
13
14
use Behat\Behat\Context\ServiceContainer\ContextExtension;
15
use Behat\Behat\Tester\ServiceContainer\TesterExtension;
16
use Behat\Testwork\Argument\ServiceContainer\ArgumentExtension;
17
use Behat\Testwork\Call\ServiceContainer\CallExtension;
18
use Behat\Testwork\EventDispatcher\ServiceContainer\EventDispatcherExtension;
19
use Behat\Testwork\Hook\ServiceContainer\HookExtension;
20
use Behat\Testwork\ServiceContainer\Extension as ExtensionInterface;
21
use Behat\Testwork\ServiceContainer\ExtensionManager;
22
use Doctrine\Common\Annotations\AnnotationReader;
23
use Doctrine\Common\Annotations\AnnotationRegistry;
24
use Gorghoa\ScenarioStateBehatExtension\Argument\ScenarioStateArgumentOrganiser;
25
use Gorghoa\ScenarioStateBehatExtension\Call\Handler\RuntimeCallHandler;
26
use Gorghoa\ScenarioStateBehatExtension\Context\Initializer\ScenarioStateInitializer;
27
use Gorghoa\ScenarioStateBehatExtension\Hook\Dispatcher\ScenarioStateHookDispatcher;
28
use Gorghoa\ScenarioStateBehatExtension\Hook\Tester\ScenarioStateHookableScenarioTester;
29
use Gorghoa\ScenarioStateBehatExtension\Resolver\ArgumentsResolver;
30
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
31
use Symfony\Component\DependencyInjection\ContainerBuilder;
32
use Symfony\Component\DependencyInjection\Reference;
33
34
/**
35
 * Behat store for Behat contexts.
36
 *
37
 * @author Rodrigue Villetard <[email protected]>
38
 * @author Vincent Chalamon <[email protected]>
39
 */
40
class ScenarioStateExtension implements ExtensionInterface
41
{
42
    const SCENARIO_STATE_ARGUMENT_ORGANISER_ID = 'argument.scenario_state.organiser';
43
    const SCENARIO_STATE_DISPATCHER_ID = 'hook.scenario_state.dispatcher';
44
    const SCENARIO_STATE_TESTER_ID = 'tester.scenario_state.wrapper';
45
    const SCENARIO_STATE_CALL_HANDLER_ID = 'call.scenario_state.call_handler';
46
    const SCENARIO_STATE_ARGUMENTS_RESOLVER_ID = 'scenario_state.arguments_resolver';
47
    const SCENARIO_STATE_STORE_ID = 'behatstore.context_initializer.store_aware';
48
    const SCENARIO_STATE_DOCTRINE_READER_ID = 'doctrine.reader.annotation';
49
50
    /**
51
     * {@inheritdoc}
52
     */
53
    public function getConfigKey()
54
    {
55
        return 'scenariostate';
56
    }
57
58
    /**
59
     * {@inheritdoc}
60
     */
61
    public function initialize(ExtensionManager $extensionManager)
62
    {
63
        AnnotationRegistry::registerFile(__DIR__.'/../Annotation/ScenarioStateArgument.php');
64
    }
65
66
    /**
67
     * {@inheritdoc}
68
     */
69
    public function configure(ArrayNodeDefinition $builder)
70
    {
71
    }
72
73
    /**
74
     * {@inheritdoc}
75
     */
76
    public function load(ContainerBuilder $container, array $config)
77
    {
78
        // Load ScenarioState store
79
        $container->register(self::SCENARIO_STATE_STORE_ID, ScenarioStateInitializer::class)
80
            ->addTag(ContextExtension::INITIALIZER_TAG, ['priority' => 0])
81
            ->addTag(EventDispatcherExtension::SUBSCRIBER_TAG, ['priority' => 0]);
82
83
        // Declare Doctrine annotation reader as service
84
        $container->register(self::SCENARIO_STATE_DOCTRINE_READER_ID, AnnotationReader::class)
85
            // Ignore Behat annotations in reader
86
            ->addMethodCall('addGlobalIgnoredName', ['Given'])
87
            ->addMethodCall('addGlobalIgnoredName', ['When'])
88
            ->addMethodCall('addGlobalIgnoredName', ['Then'])
89
            ->addMethodCall('addGlobalIgnoredName', ['Transform'])
90
            ->addMethodCall('addGlobalIgnoredName', ['BeforeStep'])
91
            ->addMethodCall('addGlobalIgnoredName', ['BeforeScenario'])
92
            ->addMethodCall('addGlobalIgnoredName', ['BeforeFeature'])
93
            ->addMethodCall('addGlobalIgnoredName', ['BeforeSuite'])
94
            ->addMethodCall('addGlobalIgnoredName', ['AfterStep'])
95
            ->addMethodCall('addGlobalIgnoredName', ['AfterScenario'])
96
            ->addMethodCall('addGlobalIgnoredName', ['AfterFeature'])
97
            ->addMethodCall('addGlobalIgnoredName', ['AfterSuite']);
98
99
        // Arguments resolver: resolve ScenarioState arguments from annotation
100
        $container->register(self::SCENARIO_STATE_ARGUMENTS_RESOLVER_ID, ArgumentsResolver::class)
101
            ->setArguments([
102
                new Reference(self::SCENARIO_STATE_STORE_ID),
103
                new Reference(self::SCENARIO_STATE_DOCTRINE_READER_ID),
104
            ]);
105
106
        // Argument organiser
107
        $container->register(self::SCENARIO_STATE_ARGUMENT_ORGANISER_ID, ScenarioStateArgumentOrganiser::class)
108
            ->setDecoratedService(ArgumentExtension::PREG_MATCH_ARGUMENT_ORGANISER_ID)
109
            ->setPublic(false)
110
            ->setArguments([
111
                new Reference(sprintf('%s.inner', self::SCENARIO_STATE_ARGUMENT_ORGANISER_ID)),
112
                new Reference(self::SCENARIO_STATE_STORE_ID),
113
                new Reference(self::SCENARIO_STATE_DOCTRINE_READER_ID),
114
                new Reference(self::SCENARIO_STATE_ARGUMENTS_RESOLVER_ID),
115
            ]);
116
117
        // Override calls process
118
        $container->register(self::SCENARIO_STATE_CALL_HANDLER_ID, RuntimeCallHandler::class)
119
            ->setDecoratedService(CallExtension::CALL_HANDLER_TAG.'.runtime')
120
            ->setArguments([
121
                new Reference(self::SCENARIO_STATE_CALL_HANDLER_ID.'.inner'),
122
                new Reference(self::SCENARIO_STATE_ARGUMENTS_RESOLVER_ID),
123
            ]);
124
    }
125
126
    /**
127
     * {@inheritdoc}
128
     */
129
    public function process(ContainerBuilder $container)
130
    {
131
    }
132
}
133