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

RunHandlerCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 4
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 6
ccs 5
cts 5
cp 1
crap 1
rs 9.4285
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