ClearConfigCache   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Test Coverage

Coverage 70.37%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 25
c 1
b 0
f 0
dl 0
loc 52
ccs 19
cts 27
cp 0.7037
rs 10
wmc 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A execute() 0 31 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
    /** @var array<mixed>  */
15
    private array $config;
16
17
    /**
18
     * @param array<mixed> $config
19
     */
20 2
    public function __construct(array $config)
21
    {
22 2
        parent::__construct();
23 2
        $this->config = $config;
24 2
    }
25
26 2
    protected function configure(): void
27
    {
28 2
        $this->setName(self::NAME)
29 2
            ->setDescription('Clear config cache files.');
30 2
    }
31
32 2
    protected function execute(InputInterface $input, OutputInterface $output): ?int
33
    {
34 2
        foreach (['config_cache_path', 'cli_config_cache_path'] as $key) {
35 2
            if (! isset($this->config[$key])) {
36 1
                $output->writeln("<comment>No configuration cache path found</comment>");
37 1
                continue;
38
            }
39
40 1
            if (! file_exists($this->config[$key])) {
41 1
                $output->writeln(sprintf(
42 1
                    "<error>Configured config cache file '%s' not found</error>",
43 1
                    $this->config[$key]
44
                ));
45 1
                continue;
46
            }
47
48
            if (false === unlink($this->config[$key])) {
49
                $output->writeln(sprintf(
50
                    "<error>Error removing config cache file '%s'</error>",
51
                    $this->config[$key]
52
                ));
53
                continue;
54
            }
55
56
            $output->writeln(sprintf(
57
                "<info>Removed configured config cache file '%s'</info>",
58
                $this->config[$key]
59
            ));
60
        }
61
62 2
        return 0;
63
    }
64
}
65