StatsCommand::execute()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 5
c 2
b 0
f 0
dl 0
loc 8
ccs 0
cts 7
cp 0
rs 10
cc 1
nc 1
nop 2
crap 2
1
<?php
2
3
namespace Tarantool\JobQueue\Console\Command;
4
5
use Symfony\Component\Console\Input\InputInterface;
6
use Symfony\Component\Console\Output\OutputInterface;
7
8
class StatsCommand extends Command
9
{
10
    protected function configure(): void
11
    {
12
        parent::configure();
13
14
        $this
15
            ->setName('stats')
16
            ->setDescription('Shows statistical information about the queue')
17
        ;
18
    }
19
20
    protected function execute(InputInterface $input, OutputInterface $output): void
21
    {
22
        $queue = $this->createConfigFactory($input, $output)->createQueue();
23
        $stats = $queue->stats();
24
25
        $output->writeln(sprintf('Queue: <options=bold>%s</>', $queue->getName()));
26
        $output->writeln('Tasks: '.self::buildLine($stats['tasks']));
27
        $output->writeln('Calls: '.self::buildLine($stats['calls']));
28
    }
29
30
    private static function buildLine(array $stats): string
31
    {
32
        $items = [];
33
        foreach ($stats as $name => $count) {
34
            $items[] = "<options=bold>$count</> $name";
35
        }
36
37
        return implode(', ', $items);
38
    }
39
}
40