Issues (62)

Command/DebugCommand.php (2 issues)

1
<?php
2
3
namespace Kaliop\eZWorkflowEngineBundle\Command;
4
5
use Kaliop\eZMigrationBundle\API\Value\MigrationDefinition;
6
use Symfony\Component\Console\Helper\Table;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Input\InputOption;
9
use Symfony\Component\Console\Output\OutputInterface;
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
            ->addOption('show-path', null, InputOption::VALUE_NONE, "Print definition path instead of notes")
22
        ;
23
    }
24
25
    public function execute(InputInterface $input, OutputInterface $output)
26
    {
27
        $workflowService = $this->getWorkflowService();
28
29
        $displayPath = $input->getOption('show-path');
30
31
        $workflowDefinitions = $workflowService->getWorkflowsDefinitions($input->getOption('path'));
0 ignored issues
show
It seems like $input->getOption('path') can also be of type boolean and string; however, parameter $paths of Kaliop\eZWorkflowEngineB...tWorkflowsDefinitions() does only seem to accept string[], maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

31
        $workflowDefinitions = $workflowService->getWorkflowsDefinitions(/** @scrutinizer ignore-type */ $input->getOption('path'));
Loading history...
32
33
        if (!count($workflowDefinitions)) {
34
            $output->writeln('<info>No workflow definitions found</info>');
35
            return 0;
36
        }
37
38
        $i = 1;
39
        foreach ($workflowDefinitions as $workflowDefinition) {
40
            switch ($workflowDefinition->status) {
41
                case MigrationDefinition::STATUS_INVALID:
42
                    $name = '<error>' . $workflowDefinition->name . '</error>';
43
                    break;
44
                default:
45
                    $name = $workflowDefinition->name;
46
            }
47
            $data[] = array(
48
                $i++,
49
                $name,
50
                $workflowDefinition->signalName,
51
                //$workflowDefinition->path,
52
                ($workflowDefinition->runAs === false) ? '-' : $workflowDefinition->runAs,
53
                $workflowDefinition->useTransaction ? 'Y' : 'N',
54
                $displayPath ? $workflowDefinition->path : $workflowDefinition->parsingError
55
            );
56
57
        }
58
59
        $table = new Table($output);
60
        $table
61
            ->setHeaders(array('#', 'Workflow definition', 'Signal', 'Switch user', 'Use transaction', /*'Path',*/ 'Notes'))
62
            ->setRows($data);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $data seems to be defined by a foreach iteration on line 39. Are you sure the iterator is never empty, otherwise this variable is not defined?
Loading history...
63
        $table->render();
64
65
        return 0;
66
    }
67
}
68