Completed
Push — master ( ce95ca...829dc5 )
by Jacob
6s
created

ClearCacheCommand   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 7
c 1
b 0
f 1
lcom 1
cbo 1
dl 0
loc 49
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A configure() 0 9 1
B execute() 0 14 5
1
<?php
2
3
namespace As3\Bundle\ModlrBundle\Command\Metadata;
4
5
use As3\Modlr\Metadata\Cache\CacheWarmer;
6
use Symfony\Component\Console\Command\Command;
7
use Symfony\Component\Console\Input\InputArgument;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Input\InputOption;
10
use Symfony\Component\Console\Output\OutputInterface;
11
12
/**
13
 * Clears/warms the metadata cache.
14
 *
15
 * @author  Jacob Bare <[email protected]>
16
 */
17
class ClearCacheCommand extends Command
18
{
19
    /**
20
     * @var CacheWarmer
21
     */
22
    private $cacheWarmer;
23
24
    /**
25
     * Constructor.
26
     *
27
     * @param   CacheWarmer     $cacheWarmer
28
     */
29
    public function __construct(CacheWarmer $cacheWarmer)
30
    {
31
        parent::__construct();
32
        $this->cacheWarmer = $cacheWarmer;
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    protected function configure()
39
    {
40
        $this
41
            ->setName('as3:modlr:metadata:cache:clear')
42
            ->setDescription('Clears/warms metadata for all models, or for a specific model.')
43
            ->addArgument('type', InputArgument::OPTIONAL, 'Specify the model type to clear.')
44
            ->addOption('no-warm', null, InputOption::VALUE_NONE, 'If set, warming will be disabled.')
45
        ;
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51
    protected function execute(InputInterface $input, OutputInterface $output)
52
    {
53
        $type = $input->getArgument('type') ?: null;
54
        $noWarm = $input->getOption('no-warm');
55
56
        $action = (true === $noWarm) ? 'Clearing' : 'Warming';
57
        $types = (null === $type) ? 'all types' : sprintf('model type "%s"', $type);
58
59
        $output->writeln(sprintf('<info>%s the metadata cache for %s</info>', $action, $types));
60
61
        $result = (true === $noWarm) ? $this->cacheWarmer->clear($type) : $this->cacheWarmer->warm($type);
62
63
        $output->writeln(sprintf('<info>Action complete for: %s</info>', implode(', ', $result)));
64
    }
65
}
66