Completed
Push — master ( 0c7a1a...95af33 )
by Wachter
12:11 queued 07:39
created

RunHandlerCommand   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 80%

Importance

Changes 4
Bugs 3 Features 3
Metric Value
wmc 5
c 4
b 3
f 3
lcom 1
cbo 4
dl 0
loc 43
ccs 16
cts 20
cp 0.8
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A configure() 0 6 1
A execute() 0 15 3
1
<?php
2
3
namespace Task\TaskBundle\Command;
4
5
use Symfony\Component\Console\Command\Command;
6
use Symfony\Component\Console\Input\InputArgument;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Output\OutputInterface;
9
use Task\Handler\RegistryInterface;
10
11
/**
12
 * Run pending tasks.
13
 *
14
 * @author Alexander Schranz <[email protected]>
15
 */
16
class RunHandlerCommand extends Command
17
{
18
    /**
19
     * @var RegistryInterface
20
     */
21
    private $registry;
22
23 18
    public function __construct($name, RegistryInterface $registry)
24
    {
25 18
        parent::__construct($name);
26
27 18
        $this->registry = $registry;
28 18
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33 18
    protected function configure()
34
    {
35 18
        $this->setDescription('Run pending tasks')
36 18
            ->addArgument('handler', InputArgument::REQUIRED)
37 18
            ->addArgument('workload', InputArgument::OPTIONAL);
38 18
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43 12
    protected function execute(InputInterface $input, OutputInterface $output)
44
    {
45 12
        $handler = $input->getArgument('handler');
46 12
        $workload = $input->getArgument('workload');
47
48 12
        if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
49
            $output->writeln(sprintf('Run command "%s" with workload "%s"', $handler, $workload));
50
        }
51
52 12
        $result = $this->registry->run($handler, $workload);
53
54 12
        if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
55
            $output->writeln(sprintf('Result: %s', json_encode($result)));
56
        }
57 12
    }
58
}
59