Passed
Push — feature/clear-cache ( e2345a )
by Arnaud
07:42
created

CacheClearTemplates::execute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 10
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 16
rs 9.9332
1
<?php
2
/**
3
 * This file is part of the Cecil/Cecil package.
4
 *
5
 * Copyright (c) Arnaud Ligny <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Cecil\Command;
12
13
use Cecil\Util;
14
use Symfony\Component\Console\Input\InputArgument;
15
use Symfony\Component\Console\Input\InputDefinition;
16
use Symfony\Component\Console\Input\InputInterface;
17
use Symfony\Component\Console\Output\OutputInterface;
18
19
/**
20
 * Removes templates cache files.
21
 */
22
class CacheClearTemplates extends AbstractCommand
23
{
24
    /**
25
     * {@inheritdoc}
26
     */
27
    protected function configure()
28
    {
29
        $this
30
            ->setName('cache:clear:templates')
31
            ->setDescription('Removes templates cache')
32
            ->setDefinition(
33
                new InputDefinition([
34
                    new InputArgument('path', InputArgument::OPTIONAL, 'Use the given path as working directory'),
35
                ])
36
            )
37
            ->setHelp('Removes cached templates files');
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    protected function execute(InputInterface $input, OutputInterface $output)
44
    {
45
        if (!$this->fs->exists(Util::joinFile($this->getBuilder()->getConfig()->getCachePath(), 'templates'))) {
46
            $output->writeln('<info>No templates cache.</info>');
47
48
            return 0;
49
        }
50
        $output->writeln('Removing templates cache directory...');
51
        $output->writeln(
52
            sprintf('<comment>Path %s</comment>', Util::joinFile($this->getBuilder()->getConfig()->getCachePath(), 'templates')),
53
            OutputInterface::VERBOSITY_VERBOSE
54
        );
55
        $this->fs->remove(Util::joinFile($this->getBuilder()->getConfig()->getCachePath(), 'templates'));
56
        $output->writeln('<info>Templates cache is clear.</info>');
57
58
        return 0;
59
    }
60
}
61