Completed
Pull Request — master (#2)
by Wachter
05:57
created

RunHandlerCommand::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 9.4286
cc 1
eloc 3
nc 1
nop 1
crap 1
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
use Task\SchedulerInterface;
11
12
/**
13
 * Run pending tasks.
14
 *
15
 * @author Alexander Schranz <[email protected]>
16
 */
17
class RunHandlerCommand extends Command
18
{
19
    /**
20
     * @var RegistryInterface
21
     */
22
    private $registry;
23
24 18
    public function __construct(RegistryInterface $registry)
25
    {
26 18
        parent::__construct('task:run:handler');
27
28 18
        $this->registry = $registry;
29 18
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34 18
    protected function configure()
35
    {
36 18
        $this->setDescription('Run pending tasks')
37 18
            ->addArgument('handler', InputArgument::REQUIRED)
38 18
            ->addArgument('workload', InputArgument::OPTIONAL);
39 18
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44 12
    protected function execute(InputInterface $input, OutputInterface $output)
45
    {
46 12
        $handler = $input->getArgument('handler');
47 12
        $workload = $input->getArgument('workload');
48
49 12
        $output->writeln(sprintf('Run command "%s" with workload "%s"', $handler, $workload));
50
51 12
        $result = $this->registry->run($handler, $workload);
52
53 12
        $output->writeln(sprintf('Result: "%s"', $result));
54 12
    }
55
}
56