Completed
Push — develop ( a89061...54507c )
by Jaap
08:53
created

Application/CilexCompatibilityLayer/Container.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
declare(strict_types=1);
4
5
namespace Pimple;
6
7
use phpDocumentor\Application\Console\Command\Command;
8
use Psr\Container\NotFoundExceptionInterface;
9
use Symfony\Component\DependencyInjection\ContainerInterface;
10
11
if (!class_exists(\Pimple\Container::class, false)) {
12
    class Container implements \ArrayAccess
13
    {
14
        /** @var ContainerInterface */
15
        protected $container;
16
17
        public function __construct(ContainerInterface $container)
18
        {
19
            $this->container = $container;
20
        }
21
22
        public function offsetExists($offset)
23
        {
24
            return $this->container->has($offset);
25
        }
26
27
        public function offsetGet($offset)
28
        {
29
            try {
30
                return $this->container->get($offset);
31
            } catch (NotFoundExceptionInterface $exception) {
32
                return null;
33
            }
34
        }
35
36
        public function offsetSet($offset, $value)
37
        {
38
            if ($value instanceof \Closure) {
39
                $value = $value($this);
40
            }
41
            $this->container->set($offset, $value);
42
        }
43
44
        public function offsetUnset($offset)
45
        {
46
            $this->container->set($offset, null);
0 ignored issues
show
null is of type null, but the function expects a object.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
47
        }
48
49
        public function register(ServiceProviderInterface $serviceProvider)
50
        {
51
            $serviceProvider->register($this);
52
        }
53
54
        public function extend(string $serviceId, \Closure $extendingService)
55
        {
56
            return $extendingService($this->container->get($serviceId));
57
        }
58
59
        public function command(Command $command)
60
        {
61
            if (! $this->container->has('phpdocumentor.compatibility.extra_commands')) {
62
                $this->container->set('phpdocumentor.compatibility.extra_commands', new \ArrayObject());
63
            }
64
            /** @var \ArrayObject $commands */
65
            $commands = $this->container->get('phpdocumentor.compatibility.extra_commands');
66
67
            $commands->append($command);
68
        }
69
    }
70
}
71