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

StepArgumentInjectorExtension::initialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
c 0
b 0
f 0
rs 10
cc 1
eloc 1
nc 1
nop 1
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\ServiceContainer;
13
14
use Behat\Testwork\Argument\ServiceContainer\ArgumentExtension;
15
use Behat\Testwork\Call\ServiceContainer\CallExtension;
16
use Behat\Testwork\ServiceContainer\Extension as ExtensionInterface;
17
use Behat\Testwork\ServiceContainer\ExtensionManager;
18
use Doctrine\Common\Annotations\AnnotationReader;
19
use Gorghoa\StepArgumentInjectorBehatExtension\Argument\ArgumentOrganiser;
20
use Gorghoa\StepArgumentInjectorBehatExtension\Call\Handler\RuntimeCallHandler;
21
use Gorghoa\StepArgumentInjectorBehatExtension\Resolver\ArgumentsResolver;
22
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
23
use Symfony\Component\DependencyInjection\ContainerBuilder;
24
use Symfony\Component\DependencyInjection\Reference;
25
26
/**
27
 * Behat store for Behat contexts.
28
 *
29
 * @author Rodrigue Villetard <[email protected]>
30
 * @author Vincent Chalamon <[email protected]>
31
 */
32
class StepArgumentInjectorExtension implements ExtensionInterface
33
{
34
    const STEP_ARGUMENT_INJECTOR_ARGUMENT_ORGANISER_ID = 'argument.step_argument_injector.organiser';
35
    const STEP_ARGUMENT_INJECTOR_DISPATCHER_ID = 'hook.step_argument_injector.dispatcher';
36
    const STEP_ARGUMENT_INJECTOR_TESTER_ID = 'tester.step_argument_injector.wrapper';
37
    const STEP_ARGUMENT_INJECTOR_CALL_HANDLER_ID = 'call.step_argument_injector.call_handler';
38
    const STEP_ARGUMENT_INJECTOR_ARGUMENTS_RESOLVER_ID = 'step_argument_injector.arguments_resolver';
39
    const STEP_ARGUMENT_INJECTOR_STORE_ID = 'behatstore.context_initializer.store_aware';
40
    const STEP_ARGUMENT_INJECTOR_DOCTRINE_READER_ID = 'doctrine.reader.annotation';
41
    const STEP_ARGUMENT_INJECTOR_HOOK_TAG_ID = 'step_argument_injector.hook_tag_id';
42
43
    /**
44
     * {@inheritdoc}
45
     */
46
    public function getConfigKey()
47
    {
48
        return 'stepargumentinjector';
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54
    public function initialize(ExtensionManager $extensionManager)
55
    {
56
    }
57
58
    /**
59
     * {@inheritdoc}
60
     */
61
    public function configure(ArrayNodeDefinition $builder)
62
    {
63
    }
64
65
    /**
66
     * {@inheritdoc}
67
     */
68
    public function load(ContainerBuilder $container, array $config)
69
    {
70
        // Declare Doctrine annotation reader as service
71
        $container->register(self::STEP_ARGUMENT_INJECTOR_DOCTRINE_READER_ID, AnnotationReader::class)
72
            // Ignore Behat annotations in reader
73
            ->addMethodCall('addGlobalIgnoredName', ['Given'])
74
            ->addMethodCall('addGlobalIgnoredName', ['When'])
75
            ->addMethodCall('addGlobalIgnoredName', ['Then'])
76
            ->addMethodCall('addGlobalIgnoredName', ['Transform'])
77
            ->addMethodCall('addGlobalIgnoredName', ['BeforeStep'])
78
            ->addMethodCall('addGlobalIgnoredName', ['BeforeScenario'])
79
            ->addMethodCall('addGlobalIgnoredName', ['BeforeFeature'])
80
            ->addMethodCall('addGlobalIgnoredName', ['BeforeSuite'])
81
            ->addMethodCall('addGlobalIgnoredName', ['AfterStep'])
82
            ->addMethodCall('addGlobalIgnoredName', ['AfterScenario'])
83
            ->addMethodCall('addGlobalIgnoredName', ['AfterFeature'])
84
            ->addMethodCall('addGlobalIgnoredName', ['AfterSuite']);
85
86
        $taggedServices = array_map(function ($serviceId) {
87
            return new Reference($serviceId);
88
        }, array_keys($container->findTaggedServiceIds(self::STEP_ARGUMENT_INJECTOR_HOOK_TAG_ID)));
89
90
        // Arguments resolver: resolve StepArgumentInjector arguments from annotation
91
        $container->register(self::STEP_ARGUMENT_INJECTOR_ARGUMENTS_RESOLVER_ID, ArgumentsResolver::class)
92
            ->setArguments([
93
                $taggedServices,
94
                new Reference(self::STEP_ARGUMENT_INJECTOR_DOCTRINE_READER_ID),
95
            ]);
96
97
        // Argument organiser
98
        $container->register(self::STEP_ARGUMENT_INJECTOR_ARGUMENT_ORGANISER_ID, ArgumentOrganiser::class)
99
            ->setDecoratedService(ArgumentExtension::PREG_MATCH_ARGUMENT_ORGANISER_ID)
100
            ->setPublic(false)
101
            ->setArguments([
102
                new Reference(sprintf('%s.inner', self::STEP_ARGUMENT_INJECTOR_ARGUMENT_ORGANISER_ID)),
103
                $taggedServices,
104
                new Reference(self::STEP_ARGUMENT_INJECTOR_DOCTRINE_READER_ID),
105
                new Reference(self::STEP_ARGUMENT_INJECTOR_ARGUMENTS_RESOLVER_ID),
106
            ]);
107
108
        // Override calls process
109
        $container->register(self::STEP_ARGUMENT_INJECTOR_CALL_HANDLER_ID, RuntimeCallHandler::class)
110
            ->setDecoratedService(CallExtension::CALL_HANDLER_TAG.'.runtime')
111
            ->setArguments([
112
                new Reference(self::STEP_ARGUMENT_INJECTOR_CALL_HANDLER_ID.'.inner'),
113
                new Reference(self::STEP_ARGUMENT_INJECTOR_ARGUMENTS_RESOLVER_ID),
114
            ]);
115
    }
116
117
    /**
118
     * {@inheritdoc}
119
     */
120
    public function process(ContainerBuilder $container)
121
    {
122
    }
123
}
124