GenericTaskRunner   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 90.91%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
c 1
b 0
f 0
lcom 1
cbo 3
dl 0
loc 45
ccs 20
cts 22
cp 0.9091
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
D executeTasks() 0 36 9
1
<?php namespace Mistletoe\Runners;
2
use Mistletoe\Command;
3
use Mistletoe\Contracts\TaskRunnerInterface;
4
use Mistletoe\Contracts\RunnableInterface;
5
use Mistletoe\TaskBag;
6
7
/**
8
 * Class Generic
9
 * @package Mistletoe\Application\Commands
10
 */
11
12
class GenericTaskRunner extends AbstractTaskRunner implements TaskRunnerInterface
13
{
14
    /**
15
     * 
16
     * This is NOT done in a try/catch block. This should be RUN inside a try/catch block!
17
     * @param array $tasks
18
     * @return mixed
19
     */
20 1
    protected function executeTasks(array $tasks)
21
    {
22 1
        if ($this->testing) {
23
            return $tasks;
24
        }
25
26 1
        $processes = [];
27
28
        /** @var TaskBag $task */
29 1
        foreach ($tasks as $task) {
30 1
            $processes[] = $task->getTask();
31 1
            $processes = array_merge($processes, $task->getFollowedBy());
32 1
        }
33
        
34 1
        foreach ($processes as $process) {
35
            // Create a Process instance
36 1
            if (is_string($process) && class_exists($process)) {
37 1
                $process = new $process();
38 1
            }
39
40
            // Try to Run that Process
41 1
            if (is_callable($process)) {
42
                $process();
43
44 1
            } elseif ($process instanceof Command) {
45 1
                exec($process->getCommand());
46
47 1
            } elseif ($process instanceof RunnableInterface) {
48
                /** @var \Mistletoe\Contracts\RunnableInterface $obj */
49 1
                $obj = new $process();
50 1
                $obj->run();
51 1
            }
52 1
        }
53
        
54 1
        return true;
55
    }
56
}
57