ClearSessionsCommand::execute()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 7
cts 7
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 2
crap 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