Completed
Pull Request — master (#30)
by Matthew
14:09 queued 11:28
created

CountCommand::execute()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 25
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 3.0146

Importance

Changes 0
Metric Value
dl 0
loc 25
ccs 15
cts 17
cp 0.8824
rs 8.8571
c 0
b 0
f 0
cc 3
eloc 15
nc 3
nop 2
crap 3.0146
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