Passed
Pull Request — master (#2)
by Koldo
02:20
created

ClearConfigCache   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 24
dl 0
loc 44
ccs 0
cts 34
cp 0
rs 10
c 0
b 0
f 0
wmc 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A execute() 0 27 5
A configure() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Antidot\DevTools\Application\Command;
6
7
use Symfony\Component\Console\Command\Command;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Output\OutputInterface;
10
11
class ClearConfigCache extends Command
12
{
13
    public const NAME = 'config:clear-cache';
14
    private $config;
15
16
    public function __construct(array $config)
17
    {
18
        parent::__construct();
19
        $this->config = $config;
20
    }
21
22
    protected function configure(): void
23
    {
24
        $this->setName(self::NAME)
25
            ->setDescription('Clear config cache files.');
26
    }
27
28
    protected function execute(InputInterface $input, OutputInterface $output)
29
    {
30
        foreach (['config_cache_path', 'cli_config_cache_path'] as $key) {
31
            if (! isset($this->config[$key])) {
32
                $output->writeln("<comment>No configuration cache path found</comment>");
33
                continue;
34
            }
35
36
            if (! file_exists($this->config[$key])) {
37
                $output->writeln(sprintf(
38
                    "<error>Configured config cache file '%s' not found</error>",
39
                    $this->config[$key]
40
                ));
41
                continue;
42
            }
43
44
            if (false === unlink($this->config[$key])) {
45
                $output->writeln(sprintf(
46
                    "<error>Error removing config cache file '%s'</error>",
47
                    $this->config[$key]
48
                ));
49
                continue;
50
            }
51
52
            $output->writeln(sprintf(
53
                "<info>Removed configured config cache file '%s'</info>",
54
                $this->config[$key]
55
            ));
56
        }
57
    }
58
}
59