Completed
Push — master ( d7bbda...0e324f )
by Kamil
06:08
created

KernelBasedContainerAccessor   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 0
loc 37
rs 10
c 1
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getService() 0 4 1
A getParameters() 0 10 2
1
<?php
2
3
/*
4
 * This file is part of the CrossContainerExtension package.
5
 *
6
 * (c) Kamil Kokot <[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 FriendsOfBehat\CrossContainerExtension;
13
14
use Symfony\Component\DependencyInjection\Container;
15
use Symfony\Component\HttpKernel\KernelInterface;
16
17
final class KernelBasedContainerAccessor implements ContainerAccessor
18
{
19
    /**
20
     * @var KernelInterface
21
     */
22
    private $kernel;
23
24
    /**
25
     * @param KernelInterface $kernel
26
     */
27
    public function __construct(KernelInterface $kernel)
28
    {
29
        $this->kernel = $kernel;
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35
    public function getService($id)
36
    {
37
        return $this->kernel->getContainer()->get($id);
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    public function getParameters()
44
    {
45
        $container = $this->kernel->getContainer();
46
47
        if (!$container instanceof Container) {
48
            throw new \DomainException('Could not get the parameters of kernel\'s container.');
49
        }
50
51
        return $container->getParameterBag()->all();
52
    }
53
}
54