Completed
Push — master ( 7a08de...9ce2ea )
by Daniel
04:39
created

ShowCommand::renderTable()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 19
ccs 0
cts 16
cp 0
rs 9.4285
cc 2
eloc 13
nc 2
nop 2
crap 6
1
<?php
2
/**
3
 * This file is part of the Commander project.
4
 *
5
 * @author Daniel Schröder <[email protected]>
6
 */
7
8
namespace GravityMedia\Commander\Console\Command;
9
10
use GravityMedia\Commander\Commander\Task;
11
use Monolog\Formatter\NormalizerFormatter;
12
use Symfony\Component\Console\Helper\Table;
13
use Symfony\Component\Console\Input\InputInterface;
14
use Symfony\Component\Console\Output\OutputInterface;
15
16
/**
17
 * Show command class.
18
 *
19
 * @package GravityMedia\Commander\Console\Command
20
 */
21
class ShowCommand extends Command
22
{
23
    /**
24
     * {@inheritdoc}
25
     */
26
    protected function configure()
27
    {
28
        parent::configure();
29
30
        $this
31
            ->setName('tasks:show')
32
            ->setDescription('Show all tasks');
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    protected function execute(InputInterface $input, OutputInterface $output)
39
    {
40
        $tasks = $this->getCommander()->getTaskManager()->findAllTasks();
41
42
        if (0 === count($tasks)) {
43
            $output->writeln('No tasks found');
44
            return;
45
        }
46
47
        $this->renderTable($tasks, $output);
48
    }
49
50
    /**
51
     * Render table.
52
     *
53
     * @param Task[]          $tasks
54
     * @param OutputInterface $output
55
     *
56
     * @return void
57
     */
58
    protected function renderTable(array $tasks, OutputInterface $output)
59
    {
60
        $table = new Table($output);
61
        $table->setHeaders(['ID', 'Priority', 'Commandline', 'PID', 'Exit Code', 'Created At', 'Updated At']);
62
63
        foreach ($tasks as $task) {
64
            $table->addRow([
65
                $task->getEntity()->getId(),
66
                $task->getEntity()->getPriority(),
67
                $task->getEntity()->getCommandline(),
68
                $task->getEntity()->getPid(),
69
                $task->getEntity()->getExitCode(),
70
                $task->getEntity()->getCreatedAt()->format(NormalizerFormatter::SIMPLE_DATE),
71
                $task->getEntity()->getUpdatedAt()->format(NormalizerFormatter::SIMPLE_DATE)
72
            ]);
73
        }
74
75
        $table->render();
76
    }
77
}
78