Completed
Push — master ( ce0f58...8ecbab )
by
unknown
01:26 queued 10s
created

BaseCacheCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 2
A getManager() 0 8 2
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
0 ignored issues
show
Deprecated Code introduced by
The class Symfony\Bundle\Framework...d\ContainerAwareCommand has been deprecated with message: since Symfony 4.2, use {@see Command} instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
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