StatsCommand   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
eloc 14
c 2
b 0
f 0
dl 0
loc 30
ccs 0
cts 23
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 8 1
A buildLine() 0 8 2
A configure() 0 7 1
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