ClearSessionsCommand   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 30
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 5 1
A execute() 0 12 2
1
<?php
2
3
namespace BrainExe\Core\Console;
4
5
use BrainExe\Core\Traits\RedisTrait;
6
use Symfony\Component\Console\Command\Command;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Output\OutputInterface;
9
use BrainExe\Core\Annotations\Command as CommandAnnotation;
10
11
/**
12
 * @CommandAnnotation
13
 */
14
class ClearSessionsCommand extends Command
15
{
16
17
    use RedisTrait;
18
19
    /**
20
     * {@inheritdoc}
21
     */
22 2
    protected function configure()
23
    {
24 2
        $this->setName('sessions:clear')
25 2
            ->setDescription('Clear all sessions');
26 2
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31 1
    protected function execute(InputInterface $input, OutputInterface $output)
32
    {
33 1
        $redis = $this->getRedis();
34
35 1
        $sessionIds = $redis->keys('sessions:*');
36
37 1
        foreach ($sessionIds as $sessionId) {
38 1
            $redis->del($sessionId);
39
        }
40
41 1
        $output->writeln(sprintf('Deleted <info>%d</info> sessions', count($sessionIds)));
42 1
    }
43
}
44