Extension   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
wmc 10
lcom 0
cbo 5
dl 0
loc 54
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getConfigKey() 0 4 1
A initialize() 0 6 2
A process() 0 3 1
A load() 0 8 1
A configure() 0 3 1
A loadClassResolver() 0 6 1
A loadHttpCallListener() 0 10 2
A getCompilerPasses() 0 4 1
1
<?php
2
3
namespace Behatch;
4
5
use Symfony\Component\Config\FileLocator;
6
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
7
use Symfony\Component\DependencyInjection\ContainerBuilder;
8
use Symfony\Component\DependencyInjection\Definition;
9
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
10
use Behat\Behat\Context\ServiceContainer\ContextExtension;
11
use Behat\Testwork\ServiceContainer\ExtensionManager;
12
use Behat\Testwork\ServiceContainer\Extension as ExtensionInterface;
13
14
class Extension implements ExtensionInterface
15
{
16
    public function getConfigKey()
17
    {
18
        return 'behatch';
19
    }
20
21
    public function initialize(ExtensionManager $extensionManager)
22
    {
23
        if (PHP_MAJOR_VERSION === 5) {
24
            @trigger_error('The behatch context extension will drop support for PHP 5 in version 4.0', E_USER_DEPRECATED);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
25
        }
26
    }
27
28
    public function process(ContainerBuilder $container)
29
    {
30
    }
31
32
    public function load(ContainerBuilder $container, array $config)
33
    {
34
        $loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/Resources/services'));
35
        $loader->load('http_call.yml');
36
37
        $this->loadClassResolver($container);
38
        $this->loadHttpCallListener($container);
39
    }
40
41
    public function configure(ArrayNodeDefinition $builder)
42
    {
43
    }
44
45
    private function loadClassResolver(ContainerBuilder $container)
46
    {
47
        $definition = new Definition('Behatch\Context\ContextClass\ClassResolver');
48
        $definition->addTag(ContextExtension::CLASS_RESOLVER_TAG);
49
        $container->setDefinition('behatch.class_resolver', $definition);
50
    }
51
52
    private function loadHttpCallListener(ContainerBuilder $container)
53
    {
54
        $processor = new \Behat\Testwork\ServiceContainer\ServiceProcessor;
55
        $references = $processor->findAndSortTaggedServices($container, 'behatch.context_voter');
56
        $definition = $container->getDefinition('behatch.context_supported.voter');
57
58
        foreach ($references as $reference) {
59
            $definition->addMethodCall('register', [$reference]);
60
        }
61
    }
62
63
    public function getCompilerPasses()
64
    {
65
        return [];
66
    }
67
}
68