Completed
Push — master ( aa9daf...c0a8a5 )
by David
10:44
created

BaseInvalidateCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 37
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A getCacheManager() 0 8 2
1
<?php
2
3
/*
4
 * This file is part of the FOSHttpCacheBundle package.
5
 *
6
 * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
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 FOS\HttpCacheBundle\Command;
13
14
use FOS\HttpCacheBundle\CacheManager;
15
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
16
17
/**
18
 * Base class for commands to trigger cache invalidation from the command line.
19
 *
20
 * @author David Buchmann <[email protected]>
21
 */
22
abstract class BaseInvalidateCommand 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 CacheManager
26
     */
27
    private $cacheManager;
28
29
    /**
30
     * If no cache manager is specified explicitly, fos_http_cache.cache_manager
31
     * is automatically loaded.
32
     *
33
     * @param CacheManager|null $cacheManager The cache manager to talk to
34
     */
35 14
    public function __construct(CacheManager $cacheManager = null)
36
    {
37 14
        if (!$cacheManager) {
38 1
            @trigger_error('Instantiating commands without the cache manager is deprecated and will be removed in version 3', E_USER_DEPRECATED);
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...
39
        }
40 14
        $this->cacheManager = $cacheManager;
41 14
        parent::__construct();
42 14
    }
43
44
    /**
45
     * Get the configured cache manager, loading fos_http_cache.cache_manager
46
     * from the container if none was specified.
47
     *
48
     * @return CacheManager
0 ignored issues
show
Documentation introduced by
Should the return type not be CacheManager|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
49
     */
50 9
    protected function getCacheManager()
51
    {
52 9
        if (!$this->cacheManager) {
53 1
            $this->cacheManager = $this->getContainer()->get('fos_http_cache.cache_manager');
54
        }
55
56 9
        return $this->cacheManager;
57
    }
58
}
59