Passed
Push — fix_i18n ( 116c3d )
by Arnaud
04:25
created

CacheClearTranslations   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
dl 0
loc 37
rs 10
c 1
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 11 1
A execute() 0 16 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of Cecil.
7
 *
8
 * Copyright (c) Arnaud Ligny <[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 Cecil\Command;
15
16
use Symfony\Component\Console\Input\InputArgument;
17
use Symfony\Component\Console\Input\InputDefinition;
18
use Symfony\Component\Console\Input\InputInterface;
19
use Symfony\Component\Console\Output\OutputInterface;
20
21
/**
22
 * Removes translations cache files.
23
 */
24
class CacheClearTranslations extends AbstractCommand
25
{
26
    /**
27
     * {@inheritdoc}
28
     */
29
    protected function configure()
30
    {
31
        $this
32
            ->setName('cache:clear:translations')
33
            ->setDescription('Removes translations cache')
34
            ->setDefinition(
35
                new InputDefinition([
36
                    new InputArgument('path', InputArgument::OPTIONAL, 'Use the given path as working directory'),
37
                ])
38
            )
39
            ->setHelp('Removes cached translations files');
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45
    protected function execute(InputInterface $input, OutputInterface $output)
46
    {
47
        if (!$this->fs->exists($this->getBuilder()->getConfig()->getCacheTranslationsPath())) {
48
            $output->writeln('<info>No translations cache.</info>');
49
50
            return 0;
51
        }
52
        $output->writeln('Removing translations cache directory...');
53
        $output->writeln(
54
            \sprintf('<comment>Path %s</comment>', $this->getBuilder()->getConfig()->getCacheTranslationsPath()),
55
            OutputInterface::VERBOSITY_VERBOSE
56
        );
57
        $this->fs->remove($this->getBuilder()->getConfig()->getCacheTranslationsPath());
58
        $output->writeln('<info>Translations cache is clear.</info>');
59
60
        return 0;
61
    }
62
}
63