Passed
Branch main (b0ee7b)
by Gaetano
09:00
created

DebugCommand::execute()   B

Complexity

Conditions 6
Paths 10

Size

Total Lines 37
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 25
c 0
b 0
f 0
nc 10
nop 2
dl 0
loc 37
rs 8.8977
1
<?php
2
3
namespace Kaliop\eZWorkflowEngineBundle\Command;
4
5
use Symfony\Component\Console\Input\InputInterface;
6
use Symfony\Component\Console\Output\OutputInterface;
7
use Symfony\Component\Console\Input\InputOption;
8
use Symfony\Component\Console\Helper\Table;
9
use Kaliop\eZMigrationBundle\API\Value\MigrationDefinition;
10
11
/**
12
 * Command to display the defined workflow definitions.
13
 */
14
class DebugCommand extends AbstractCommand
15
{
16
    protected function configure()
17
    {
18
        $this->setName('kaliop:workflows:debug')
19
            ->setDescription('List the configured workflow definitions')
20
            ->addOption('path', null, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, "The directory or file to load the workflow definitions from"
21
            )
22
        ;
23
    }
24
25
    public function execute(InputInterface $input, OutputInterface $output)
26
    {
27
        $workflowService = $this->getWorkflowService();
28
29
        $workflowDefinitions = $workflowService->getWorkflowsDefinitions($input->getOption('path'));
30
31
        if (!count($workflowDefinitions)) {
32
            $output->writeln('<info>No workflow definitions found</info>');
33
            return;
34
        }
35
36
        $i = 1;
37
        foreach ($workflowDefinitions as $workflowDefinition) {
38
            switch ($workflowDefinition->status) {
39
                case MigrationDefinition::STATUS_INVALID:
40
                    $name = '<error>' . $workflowDefinition->name . '</error>';
41
                    break;
42
                default:
43
                    $name = $workflowDefinition->name;
44
            }
45
            $data[] = array(
46
                $i++,
47
                $name,
48
                $workflowDefinition->signalName,
49
                //$workflowDefinition->path,
50
                ($workflowDefinition->runAs === false) ? '-' : $workflowDefinition->runAs,
51
                $workflowDefinition->useTransaction ? 'Y' : 'N',
52
                $workflowDefinition->parsingError
53
            );
54
55
        }
56
57
        $table = new Table($output);
58
        $table
59
            ->setHeaders(array('#', 'Workflow definition', 'Signal', 'Switch user', 'Use transaction', /*'Path',*/ 'Notes'))
60
            ->setRows($data);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $data seems to be defined by a foreach iteration on line 37. Are you sure the iterator is never empty, otherwise this variable is not defined?
Loading history...
61
        $table->render();
62
    }
63
}
64