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

RunHandlerCommand   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

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
ccs 16
cts 16
cp 1
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 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