ContainerWrapper::setContainer()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 2
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 5
rs 10
1
<?php
2
3
namespace Lagdo\Facades;
4
5
use Psr\Container\ContainerExceptionInterface;
6
use Psr\Container\ContainerInterface;
7
use Psr\Container\NotFoundExceptionInterface;
8
9
final class ContainerWrapper
10
{
11
    /**
12
     * @var ContainerInterface|null
13
     */
14
    private static ContainerInterface|null $container = null;
15
16
    /**
17
     * @param ContainerInterface $container
18
     * @param bool $overwrite
19
     *
20
     * @return void
21
     */
22
    public static function setContainer(ContainerInterface $container, bool $overwrite = true): void
23
    {
24
        if($overwrite || self::$container === null)
25
        {
26
            self::$container = $container;
27
        }
28
    }
29
30
    /**
31
     * Get a service using the container.
32
     *
33
     * @param string $serviceId
34
     *
35
     * @return mixed
36
     * @throws ContainerExceptionInterface
37
     * @throws NotFoundExceptionInterface
38
     */
39
    public static function getFacadeService(string $serviceId): mixed
40
    {
41
        return self::$container->get($serviceId);
0 ignored issues
show
Bug introduced by
The method get() does not exist on null. ( Ignorable by Annotation )

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

41
        return self::$container->/** @scrutinizer ignore-call */ get($serviceId);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
42
    }
43
}
44