Completed
Push — master ( 329666...b8b013 )
by Wachter
06:11
created

RunHandlerCommand   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 2
Bugs 1 Features 2
Metric Value
wmc 3
c 2
b 1
f 2
lcom 1
cbo 4
dl 0
loc 39
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A configure() 0 6 1
A execute() 0 11 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
    public function __construct(RegistryInterface $registry)
25
    {
26
        parent::__construct('task:run:handler');
27
28
        $this->registry = $registry;
29
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34
    protected function configure()
35
    {
36
        $this->setDescription('Run pending tasks')
37
            ->addArgument('handler', InputArgument::REQUIRED)
38
            ->addArgument('workload', InputArgument::OPTIONAL);
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    protected function execute(InputInterface $input, OutputInterface $output)
45
    {
46
        $handler = $input->getArgument('handler');
47
        $workload = $input->getArgument('workload');
48
49
        $output->writeln(sprintf('Run command "%s" with workload "%s"', $handler, $workload));
50
51
        $result = $this->registry->run($handler, $workload);
52
53
        $output->writeln(sprintf('Result: "%s"', $result));
54
    }
55
}
56