Completed
Push — master ( 55a9c0...ed128c )
by Emil
14:56
created

RunCommand   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 5
dl 0
loc 42
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 7 1
B execute() 0 25 4
1
<?php
2
3
namespace Glooby\TaskBundle\Command\Task;
4
5
use Doctrine\ORM\NoResultException;
6
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
7
use Symfony\Component\Console\Input\InputArgument;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Input\InputOption;
10
use Symfony\Component\Console\Output\OutputInterface;
11
12
/**
13
 * @author Emil Kilhage
14
 */
15
class RunCommand extends ContainerAwareCommand
16
{
17
    /**
18
     * Configures the current command.
19
     */
20
    protected function configure()
21
    {
22
        $this->setName('task:run');
23
        $this->addArgument('service', InputArgument::OPTIONAL);
24
        $this->addOption('silent', 'S', InputOption::VALUE_NONE);
25
        $this->addOption('id', null, InputOption::VALUE_REQUIRED);
26
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    protected function execute(InputInterface $input, OutputInterface $output)
32
    {
33
        $runner = $this->getContainer()->get('glooby_task.task_runner');
34
        $runner->setOutput($output);
35
36
        if ($input->getOption('id')) {
37
            $task = $this->getContainer()
38
                ->get('doctrine')
39
                ->getManager()
40
                ->getRepository('GloobyTaskBundle:QueuedTask')
41
                ->find($input->getOption('id'));
42
43
            if (null === $task) {
44
                throw new NoResultException();
45
            }
46
47
            $runner->run($task);
48
        } else {
49
            $response = $runner->runTask($input->getArgument('service'));
50
51
            if (!$input->getOption('silent')) {
52
                $output->writeln($response);
53
            }
54
        }
55
    }
56
}
57