Passed
Push — master ( 8b8928...9eea0d )
by Andreas
11:05
created

cacheinvalidate   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 29
ccs 0
cts 11
cp 0
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 11 2
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;
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
use Symfony\Component\Console\Attribute\AsCommand;
17
18
/**
19
 * clear the cache of the current site
20
 *
21
 * @see midcom_services_cache
22
 * @package midcom.console
23
 */
24
#[AsCommand(
25
    name: 'midcom:cache-invalidate',
26
    description: 'Clears the cache',
27
    aliases: ['cache-invalidate']
28
)]
29
class cacheinvalidate extends Command
30
{
31
    private midcom_services_cache $cache;
32
33
    private string $cachedir;
34
35
    public function __construct(midcom_services_cache $cache, string $cachedir)
36
    {
37
        $this->cache = $cache;
38
        $this->cachedir = $cachedir;
39
        parent::__construct();
40
    }
41
42
    protected function execute(InputInterface $input, OutputInterface $output) : int
43
    {
44
        try {
45
            $this->cache->invalidate_all();
46
        } catch (\Throwable $e) {
47
            $output->writeln($e->getMessage());
48
        }
49
50
        $fs = new Filesystem;
51
        $fs->remove([$this->cachedir]);
52
        return Command::SUCCESS;
53
    }
54
}
55