ContainerBasedContainerAccessor::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the CrossContainerExtension package.
7
 *
8
 * (c) Kamil Kokot <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace FriendsOfBehat\CrossContainerExtension;
15
use Symfony\Component\DependencyInjection\Container;
16
use Symfony\Component\DependencyInjection\ContainerInterface;
17
18
final class ContainerBasedContainerAccessor implements ContainerAccessor
19
{
20
    /**
21
     * @var Container
22
     */
23
    private $container;
24
25
    /**
26
     * @param Container $container
27
     */
28
    public function __construct(ContainerInterface $container)
29
    {
30
        $this->container = $container;
0 ignored issues
show
Documentation Bug introduced by
$container is of type object<Symfony\Component...ion\ContainerInterface>, but the property $container was declared to be of type object<Symfony\Component...ncyInjection\Container>. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    public function getService(string $id)
37
    {
38
        return $this->container->get($id);
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    public function getParameters(): array
45
    {
46
        $parameterBag = $this->container->getParameterBag();
47
48
        if (!$this->container->isCompiled()) {
49
            $parameterBag = clone $parameterBag;
50
            $parameterBag->resolve();
51
        }
52
53
        return array_map(function ($unescapedValue) use ($parameterBag) {
54
            return $parameterBag->escapeValue($unescapedValue);
55
        }, $parameterBag->all());
56
    }
57
}
58