Passed
Push — master ( 9b342b...cbda31 )
by San
02:50
created

src/Extension.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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