Completed
Pull Request — master (#2)
by Pol
04:31 queued 01:52
created

RunTask   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 41
ccs 0
cts 19
cp 0
rs 10
c 0
b 0
f 0
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A run() 0 30 4
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace PhpTaskman\Core\Plugin\Task;
6
7
use PhpTaskman\Core\Plugin\BaseTask;
8
use Robo\Common\BuilderAwareTrait;
9
use Robo\Robo;
10
use Robo\Task\Base\loadTasks;
11
12
final class RunTask extends BaseTask
13
{
14
    use BuilderAwareTrait;
15
    use loadTasks;
16
17
    public const ARGUMENTS = [];
18
    public const NAME = 'run';
19
20
    /**
21
     * {@inheritdoc}
22
     */
23
    public function run()
24
    {
25
        $arguments = $this->getTaskArguments();
26
27
        $taskExec = $this->taskExec(
28
            $this->getConfig()->get('taskman.bin_dir') . '/taskman'
29
        )->arg($arguments['command']);
30
31
        $container = Robo::getContainer();
32
33
        /** @var \Robo\Application $app */
34
        $app = $container->get('application');
35
36
        /** @var \Consolidation\AnnotatedCommand\AnnotatedCommand $command */
37
        $command = $app->get($arguments['command']);
38
        $commandOptions = $command->getDefinition()->getOptions();
39
40
        // Propagate any input option passed to the child command.
41
        foreach ($arguments['options'] as $name => $values) {
42
            if (!isset($commandOptions[$name])) {
43
                continue;
44
            }
45
46
            // But only if the called command has this option.
47
            foreach ((array) $values as $value) {
48
                $taskExec->option($name, $value);
49
            }
50
        }
51
52
        return $taskExec->run();
53
    }
54
}
55