Passed
Push — master ( 83015f...73f563 )
by Stanislau
02:53
created

ClearCacheCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
dl 0
loc 35
ccs 18
cts 18
cp 1
rs 10
c 1
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A configure() 0 12 1
A execute() 0 13 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 *  This file is part of the Micro framework package.
7
 *
8
 *  (c) Stanislau Komar <[email protected]>
9
 *
10
 *  For the full copyright and license information, please view the LICENSE
11
 *  file that was distributed with this source code.
12
 */
13
14
namespace Micro\Plugin\Cache\Communication\Cli;
15
16
use Micro\Plugin\Cache\Facade\CacheFacadeInterface;
17
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...
18
use Symfony\Component\Console\Input\InputArgument;
19
use Symfony\Component\Console\Input\InputInterface;
20
use Symfony\Component\Console\Output\OutputInterface;
21
use Symfony\Component\Console\Style\SymfonyStyle;
22
23
class ClearCacheCommand extends Command
24
{
25 1
    public function __construct(
26
        private readonly CacheFacadeInterface $cacheFacade
27
    ) {
28 1
        parent::__construct('cache:clear');
29
    }
30
31 1
    public function configure(): void
32
    {
33 1
        $this
34 1
            ->addArgument('pools', InputArgument::REQUIRED | InputArgument::IS_ARRAY, 'A list of cache pools or cache pool clearer\'s')
35 1
            ->setHelp(
36 1
                <<<'EOF'
37
The <info>%command.name%</info> command clears the given cache pools or cache pool clearer\'s.
38
39
    %command.full_name% <cache pool or clearer 1> [...<cache pool or clearer N>]
40 1
EOF
41 1
            )
42 1
            ->setDescription('Clear cache pools');
43
    }
44
45 1
    public function execute(InputInterface $input, OutputInterface $output)
46
    {
47 1
        $io = new SymfonyStyle($input, $output);
48
49 1
        foreach ($input->getArgument('pools') as $poolName) {
50 1
            $io->comment(sprintf('Clearing cache pool: <info>%s</info>', $poolName));
51 1
            $pool = $this->cacheFacade->getCachePsr6($poolName);
52 1
            $pool->clear();
53
        }
54
55 1
        $io->success('Cache was successfully cleared.');
56
57 1
        return self::SUCCESS;
58
    }
59
}
60