Completed
Push — master ( 16d212...b7b31c )
by Matthew
07:34 queued 05:11
created

CountCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 90.91%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 4
dl 0
loc 35
ccs 20
cts 22
cp 0.9091
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 6 1
B execute() 0 25 3
1
<?php
2
3
namespace Dtc\QueueBundle\Command;
4
5
use Dtc\QueueBundle\Beanstalkd\JobManager;
6
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Output\OutputInterface;
9
10
class CountCommand extends ContainerAwareCommand
11
{
12 4
    protected function configure()
13
    {
14 4
        $this
15 4
            ->setName('dtc:queue:count')
16 4
            ->setDescription('Display job queue status.');
17 4
    }
18
19 4
    protected function execute(InputInterface $input, OutputInterface $output)
20
    {
21 4
        $container = $this->getContainer();
22 4
        $jobManager = $container->get('dtc_queue.job_manager');
23
24 4
        if ($jobManager instanceof JobManager) {
25 1
            $output->writeln(print_r($jobManager->getStats(), true));
26
27 1
            return 0;
28
        }
29
30 3
        $count = $jobManager->getJobCount();
31
32 3
        $format = '%-50s %8s %8s %8s %8s';
33 3
        $status = $jobManager->getStatus();
34 3
        $msg = sprintf($format, 'Job name', 'Success', 'New', 'Running', 'Error');
35 3
        $output->writeln($msg);
36
37 3
        foreach ($status as $func => $info) {
38
            $msg = sprintf($format, $func, $info['success'], $info['new'], $info['running'], $info['error']);
39
            $output->writeln($msg);
40 2
        }
41
42 2
        $output->writeln("Total jobs: {$count}");
43 2
    }
44
}
45