Completed
Push — master ( 82bcf8...197f8d )
by Alexis
03:41
created

ContainerAwareCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getContainer() 0 13 3
A setContainer() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the awurth/silex-user package.
5
 *
6
 * (c) Alexis Wurth <[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 AWurth\SilexUser\Command;
13
14
use LogicException;
15
use Psr\Container\ContainerInterface;
16
use Symfony\Component\Console\Command\Command;
17
18
/**
19
 * Command.
20
 *
21
 * @author Fabien Potencier <[email protected]>
22
 */
23
abstract class ContainerAwareCommand extends Command
24
{
25
    /**
26
     * @var ContainerInterface|null
27
     */
28
    private $container;
29
30
    /**
31
     * @return ContainerInterface
32
     *
33
     * @throws LogicException
34
     */
35
    protected function getContainer()
36
    {
37
        if (null === $this->container) {
38
            $application = $this->getApplication();
39
            if (null === $application) {
40
                throw new LogicException('The container cannot be retrieved as the application instance is not yet set.');
41
            }
42
43
            $this->container = $application->getKernel()->getContainer();
0 ignored issues
show
Bug introduced by
The method getKernel() does not seem to exist on object<Symfony\Component\Console\Application>.

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...
44
        }
45
46
        return $this->container;
47
    }
48
49
    /**
50
     * Sets the container.
51
     *
52
     * @param ContainerInterface|null $container A ContainerInterface instance or null
53
     */
54
    public function setContainer(ContainerInterface $container = null)
55
    {
56
        $this->container = $container;
57
    }
58
}
59