BaseCacheCommand::getManager()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[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 Sonata\CacheBundle\Command;
15
16
use Sonata\Cache\CacheManagerInterface;
17
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
18
19
/**
20
 * NEXT_MAJOR: stop extending ContainerAwareCommand.
21
 */
22
abstract class BaseCacheCommand extends ContainerAwareCommand
23
{
24
    /**
25
     * @var ?CacheManagerInterface
26
     */
27
    private $cacheManager;
28
29
    public function __construct(
30
        string $name = null,
31
        CacheManagerInterface $cacheManager = null
32
    ) {
33
        parent::__construct($name);
34
        if (null === $cacheManager) {
35
            @trigger_error(sprintf(
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
36
                'Not providing a cache manager to "%s" is deprecated since 3.x and will no longer be possible in 4.0',
37
                \get_class($this)
38
            ), E_USER_DEPRECATED);
39
        }
40
        $this->cacheManager = $cacheManager;
41
    }
42
43
    public function getManager(): CacheManagerInterface
44
    {
45
        if (null === $this->cacheManager) {
46
            return $this->getContainer()->get(CacheManagerInterface::class);
47
        }
48
49
        return $this->cacheManager;
50
    }
51
}
52