Passed
Push — master ( 3252a3...420639 )
by Andreas
23:53
created

cacheinvalidate   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 31
ccs 0
cts 15
cp 0
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 11 2
A configure() 0 5 1
A __construct() 0 5 1
1
<?php
2
/**
3
 * @package midcom.console
4
 * @author CONTENT CONTROL http://www.contentcontrol-berlin.de/
5
 * @copyright CONTENT CONTROL http://www.contentcontrol-berlin.de/
6
 * @license http://www.gnu.org/licenses/gpl.html GNU General Public License
7
 */
8
9
namespace midcom\console\command;
10
11
use Symfony\Component\Console\Command\Command;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Console\Command\Command was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
use Symfony\Component\Console\Input\InputInterface;
13
use Symfony\Component\Console\Output\OutputInterface;
14
use midcom_services_cache;
15
use Symfony\Component\Filesystem\Filesystem;
16
17
/**
18
 * clear the cache of the current site
19
 *
20
 * @see midcom_services_cache
21
 * @package midcom.console
22
 */
23
class cacheinvalidate extends Command
24
{
25
    private midcom_services_cache $cache;
26
27
    private string $cachedir;
28
29
    public function __construct(midcom_services_cache $cache, string $cachedir)
30
    {
31
        $this->cache = $cache;
32
        $this->cachedir = $cachedir;
33
        parent::__construct();
34
    }
35
36
    protected function configure()
37
    {
38
        $this->setName('midcom:cache-invalidate')
39
            ->setAliases(['cache-invalidate'])
40
            ->setDescription('Clears the cache');
41
    }
42
43
    protected function execute(InputInterface $input, OutputInterface $output) : int
44
    {
45
        try {
46
            $this->cache->invalidate_all();
47
        } catch (\Throwable $e) {
48
            $output->writeln($e->getMessage());
49
        }
50
51
        $fs = new Filesystem;
52
        $fs->remove([$this->cachedir]);
53
        return 0;
54
    }
55
}
56