InfoCommand   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Dependencies 7

Importance

Changes 0
Metric Value
wmc 7
cbo 7
dl 0
loc 63
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 18 1
B doExecute() 0 35 6
1
<?php
2
3
/**
4
 * This file is part of Bldr.io
5
 *
6
 * (c) Aaron Scherer <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE
10
 */
11
12
namespace Bldr\Block\Core\Command\Task;
13
14
use Bldr\Block\Core\Task\AbstractTask;
15
use Bldr\Command\AbstractCommand;
16
use Symfony\Component\Console\Helper\Table;
17
use Symfony\Component\Console\Helper\TableHelper;
18
use Symfony\Component\Console\Helper\TableStyle;
19
use Symfony\Component\Console\Input\InputArgument;
20
21
/**
22
 * @author Aaron Scherer <[email protected]>
23
 */
24
class InfoCommand extends AbstractCommand
25
{
26
    /**
27
     * {@inheritDoc}
28
     */
29
    protected function configure()
30
    {
31
        $this->setName('task:info')
32
            ->setDescription('Lists all the options for the given task.')
33
            ->addArgument('task', InputArgument::REQUIRED, 'The task to list info for')
34
            ->setHelp(
35
                <<<EOF
36
37
The <info>%command.name%</info> lists all the options for a specified task.
38
39
To use:
40
41
    <info>$ bldr %command.name% <task_name></info>
42
43
EOF
44
            )
45
        ;
46
    }
47
48
    /**
49
     * {@inheritDoc}
50
     */
51
    protected function doExecute()
52
    {
53
        /** @type AbstractTask $service */
54
        $service = $this->container->get('bldr.registry.task')->findTaskByType($this->input->getArgument('task'));
55
56
        $this->output->writeln('');
57
        $this->output->writeln('<fg=green>Task Name</fg=green>: '.$service->getName());
58
        if ($service->getDescription() !== null) {
59
            $this->output->writeln('<fg=green>Task Description</fg=green>: '.$service->getDescription());
60
        }
61
62
        if ($service instanceof AbstractTask) {
63
            $this->output->writeln(['', '<fg=green>Options:</fg=green>']);
64
            $tableHelper = new Table($this->output);
65
66
            $style = new TableStyle();
67
            $style->setCellHeaderFormat('<fg=red>%s</fg=red>');
68
            $style->setCellRowFormat('<fg=blue>%s</fg=blue>');
69
            $style->setBorderFormat('<fg=yellow>%s</fg=yellow>');
70
            $tableHelper->setStyle($style);
71
72
            $tableHelper->setHeaders(['Option', 'Description', 'Required', "Default"]);
73
            foreach ($service->getParameterDefinition() as $option) {
74
                $tableHelper->addRow(
75
                    [
76
                        $option['name'],
77
                        $option['description'] !== '' ? $option['description'] : 'No Description',
78
                        $option['required'] ? 'Yes' : 'No',
79
                        json_encode($option['default'])
80
                    ]
81
                );
82
            }
83
            $tableHelper->render();
84
        }
85
    }
86
}
87