CacheClear   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 20
dl 0
loc 39
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 10 1
A execute() 0 16 2
1
<?php
2
3
/**
4
 * This file is part of Cecil.
5
 *
6
 * (c) Arnaud Ligny <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Cecil\Command;
15
16
use Cecil\Util;
17
use Symfony\Component\Console\Input\InputArgument;
18
use Symfony\Component\Console\Input\InputInterface;
19
use Symfony\Component\Console\Output\OutputInterface;
20
21
/**
22
 * CacheClear command.
23
 *
24
 * This command removes all cached files from the cache directory.
25
 * It can be used to clear the cache before a new build or to free up space.
26
 */
27
class CacheClear extends AbstractCommand
28
{
29
    /**
30
     * {@inheritdoc}
31
     */
32
    protected function configure()
33
    {
34
        $this
35
            ->setName('cache:clear')
36
            ->setDescription('Removes all cache files')
37
            ->setDefinition([
38
                new InputArgument('path', InputArgument::OPTIONAL, 'Use the given path as working directory'),
39
            ])
40
            ->setHelp(
41
                <<<'EOF'
42
The <info>%command.name%</> command removes all cached files.
43
EOF
44
            );
45
    }
46
47
    /**
48
     * {@inheritdoc}
49
     */
50
    protected function execute(InputInterface $input, OutputInterface $output)
51
    {
52
        if (!Util\File::getFS()->exists($this->getBuilder()->getConfig()->getCachePath())) {
53
            $output->writeln('<info>No cache.</info>');
54
55
            return 0;
56
        }
57
        $output->writeln('Removing cache directory...');
58
        $output->writeln(
59
            \sprintf('<comment>Path: %s</comment>', $this->getBuilder()->getConfig()->getCachePath()),
60
            OutputInterface::VERBOSITY_VERBOSE
61
        );
62
        Util\File::getFS()->remove($this->getBuilder()->getConfig()->getCachePath());
63
        $output->writeln('<info>Cache is clear.</info>');
64
65
        return 0;
66
    }
67
}
68