BehatRSTSpecificationLocatorExtension   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 22
c 2
b 0
f 0
dl 0
loc 48
rs 10
wmc 7

5 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 14 2
A process() 0 2 1
A load() 0 13 2
A initialize() 0 2 1
A getConfigKey() 0 3 1
1
<?php
2
3
namespace Bex\Behat\BehatRSTSpecificationLocatorExtension\ServiceContainer;
4
5
use Behat\Gherkin\Cache\FileCache;
6
use Behat\Gherkin\Cache\MemoryCache;
7
use Behat\Testwork\ServiceContainer\Extension;
8
use Behat\Testwork\ServiceContainer\ExtensionManager;
9
use Bex\Behat\BehatRSTSpecificationLocatorExtension\RST\Loader\RSTFileLoader;
10
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
11
use Symfony\Component\Config\FileLocator;
12
use Symfony\Component\DependencyInjection\ContainerBuilder;
13
use Symfony\Component\DependencyInjection\Definition;
14
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
15
16
class BehatRSTSpecificationLocatorExtension implements Extension
17
{
18
    private const CONFIG_KEY = 'bex_rst_specification_locator';
19
20
    public function getConfigKey()
21
    {
22
        return self::CONFIG_KEY;
23
    }
24
25
    public function initialize(ExtensionManager $extensionManager)
26
    {
27
        // no-op
28
    }
29
30
    public function configure(ArrayNodeDefinition $builder)
31
    {
32
        $builder
33
            ->addDefaultsIfNotSet()
34
                ->children()
35
                    ->scalarNode('cache')
36
                        ->info('Sets the rst gherkin parser cache folder')
37
                        ->defaultValue(
38
                            is_writable(sys_get_temp_dir())
39
                                ? sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'behat_rst_gherkin_cache'
40
                                : null
41
                        )
42
                    ->end()
43
                ->end()
0 ignored issues
show
Bug introduced by
The method end() does not exist on Symfony\Component\Config...der\NodeParentInterface. It seems like you code against a sub-type of said class. However, the method does not exist in Symfony\Component\Config...ion\Builder\TreeBuilder. Are you sure you never get one of those? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

43
                ->/** @scrutinizer ignore-call */ end()
Loading history...
44
        ;
45
    }
46
47
    public function load(ContainerBuilder $container, array $config)
48
    {
49
        $loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/config'));
50
        $loader->load('services.yml');
51
        $container->getDefinition(Config::class)->addArgument($config);
52
53
        if (!empty($config['cache'])) {
54
            $cacheDefinition = new Definition(FileCache::class, array($config['cache']));
55
        } else {
56
            $cacheDefinition = new Definition(MemoryCache::class);
57
        }
58
59
        $container->getDefinition(RSTFileLoader::class)->setArgument('$cache', $cacheDefinition);
60
    }
61
62
    public function process(ContainerBuilder $container)
63
    {
64
        // no-op
65
    }
66
}
67