Completed
Push — master ( 7a2646...0598e0 )
by Simonas
02:15
created

CacheClearCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 0
loc 43
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 13 1
A execute() 0 20 3
1
<?php
2
3
/*
4
 * This file is part of the ONGR package.
5
 *
6
 * (c) NFQ Technologies UAB <[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
namespace ONGR\SettingsBundle\Command;
13
14
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
15
use Symfony\Component\Console\Input\InputArgument;
16
use Symfony\Component\Console\Input\InputInterface;
17
use Symfony\Component\Console\Output\OutputInterface;
18
use Symfony\Component\Console\Style\SymfonyStyle;
19
20
class CacheClearCommand extends ContainerAwareCommand
21
{
22
    /**
23
     * {@inheritdoc}
24
     */
25
    protected function configure()
26
    {
27
        parent::configure();
28
29
        $this
30
            ->setName('ongr:settings:cache:clear')
31
            ->setDescription('Clears a selected setting from cache.')
32
            ->addArgument(
33
                'setting_name',
34
                InputArgument::REQUIRED,
35
                'Setting name to remove from cache'
36
            );
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42
    protected function execute(InputInterface $input, OutputInterface $output)
43
    {
44
        $io = new SymfonyStyle($input, $output);
45
46
        if (!$this->getContainer()->has('ong_settings.cache_provider')) {
47
            throw new \RuntimeException('`ong_settings.cache_provider` service not available');
48
        }
49
50
        $cache = $this->getContainer()->get('ong_settings.cache_provider');
51
        $setting = $input->getArgument('setting_name');
52
53
        if (!$cache->contains($setting)) {
54
            $io->note(sprintf('Cache does not contain a setting named `%s`', $setting));
55
            return;
56
        }
57
58
        $cache->delete($setting);
59
60
        $io->success(sprintf('`%s` has been successfully cleared from cache', $setting));
61
    }
62
}
63