Completed
Pull Request — master (#2)
by Pol
02:43
created

RunTask   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 20
dl 0
loc 45
ccs 0
cts 21
cp 0
rs 10
c 0
b 0
f 0
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A run() 0 34 5
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\Exception\TaskException;
10
use Robo\Robo;
11
use Robo\Task\Base\loadTasks;
12
13
final class RunTask extends BaseTask
14
{
15
    use BuilderAwareTrait;
16
    use loadTasks;
17
18
    public const ARGUMENTS = [];
19
    public const NAME = 'run';
20
21
    /**
22
     * {@inheritdoc}
23
     */
24
    public function run()
25
    {
26
        $arguments = $this->getTaskArguments();
27
28
        $bin = \realpath(__DIR__ . '/../../../' . $this->getConfig()->get('taskman.bin_dir') . '/taskman');
29
30
        if (false === $bin) {
31
            throw new TaskException(__CLASS__, 'Unable to find the taskman binary');
32
        }
33
34
        $taskExec = $this->taskExec($bin)->arg($arguments['command']);
35
36
        $container = Robo::getContainer();
37
38
        /** @var \Robo\Application $app */
39
        $app = $container->get('application');
40
41
        /** @var \Consolidation\AnnotatedCommand\AnnotatedCommand $command */
42
        $command = $app->get($arguments['command']);
43
        $commandOptions = $command->getDefinition()->getOptions();
44
45
        // Propagate any input option passed to the child command.
46
        foreach ($arguments['options'] as $name => $values) {
47
            if (!isset($commandOptions[$name])) {
48
                continue;
49
            }
50
51
            // But only if the called command has this option.
52
            foreach ((array) $values as $value) {
53
                $taskExec->option($name, $value);
54
            }
55
        }
56
57
        return $taskExec->run();
58
    }
59
}
60