PurgeCommand   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 6
Bugs 0 Features 2
Metric Value
wmc 5
c 6
b 0
f 2
lcom 0
cbo 4
dl 0
loc 39
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 14 4
A configure() 0 15 1
1
<?php
2
3
namespace Sleepness\UberTranslationBundle\Command;
4
5
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
6
use Symfony\Component\Console\Input\InputInterface;
7
use Symfony\Component\Console\Output\OutputInterface;
8
9
/**
10
 * Remove all translation of application from memcache
11
 *
12
 * @author Viktor Novikov <[email protected]>
13
 */
14
class PurgeCommand extends ContainerAwareCommand
15
{
16
    /**
17
     * {@inheritdoc}
18
     */
19
    protected function configure()
20
    {
21
        $this
22
            ->setName('uber:translations:purge')
23
            ->setDefinition(array())
24
            ->setDescription('Remove all items from memcached')
25
            ->setHelp("
26
The <info>uber:translations:purge</info> command delete all translations from memcached:
27
28
Command example:
29
30
  <info>./app/console uber:translations:purge</info>
31
32
            ");
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    protected function execute(InputInterface $input, OutputInterface $output)
39
    {
40
        $container = $this->getContainer();
41
        $memcached = $container->get('uber.memcached'); // get uber memcached
42
        $keys = $container->getParameter('sleepness_uber_translation.supported_locales');
43
        foreach ($keys as $index => $locale) {
44
            if (!preg_match('/^[a-z]{2}_[a-zA-Z]{2}$|[a-z]{2}/', $locale)) {
45
                continue;
46
            }
47
            $response = $memcached->deleteItem($locale) ? "\033[37;42m Translations for " . $locale . " locale deleted from Memcache! \033[0m"
48
                : "\033[37;43m Data with " . $locale . " locale has not been deleted from Memcache! \033[0m";
49
            $output->writeln($response);
50
        }
51
    }
52
}
53