GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

ScriptManager::getTasks()   A
last analyzed

Complexity

Conditions 6
Paths 3

Size

Total Lines 24
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 13.776

Importance

Changes 0
Metric Value
eloc 16
nc 3
nop 1
dl 0
loc 24
c 0
b 0
f 0
cc 6
rs 9.1111
ccs 6
cts 15
cp 0.4
crap 13.776
1
<?php
2
/* (c) Anton Medvedev <[email protected]>
3
 *
4
 * For the full copyright and license information, please view the LICENSE
5
 * file that was distributed with this source code.
6
 */
7
8
namespace Deployer\Task;
9
10
use Deployer\Exception\Exception;
11
use function Deployer\Support\array_flatten;
12
13
class ScriptManager
14
{
15
    private $tasks;
16
    private $hooksEnabled = true;
17
    private $startFrom = null;
18
19 17
    public function __construct(TaskCollection $tasks)
20
    {
21 17
        $this->tasks = $tasks;
22 17
    }
23
24
    /**
25
     * Return tasks to run.
26
     *
27
     * @return Task[]
28
     */
29 17
    public function getTasks(string $name)
30
    {
31 17
        $tasks = [];
32 17
        $allTasks = $this->doGetTasks($name);
33
34 15
        if ($this->startFrom === null) {
35 15
            $tasks = $allTasks;
36
        } else {
37
            $skip = true;
38
            foreach ($allTasks as $task) {
39
                if ($skip) {
40
                    if ($task->getName() === $this->startFrom) {
41
                        $skip = false;
42
                    } else {
43
                        continue;
44
                    }
45
                }
46
                $tasks[] = $task;
47
            }
48
            if (count($tasks) === 0) {
49
                throw new Exception('All tasks skipped via --start-from option. Nothing to run.');
50
            }
51
        }
52 15
        return $tasks;
53
    }
54
55
    /**
56
     * @param string $name
57
     * @return Task[]
58
     */
59 17
    public function doGetTasks(string $name)
60
    {
61 17
        $tasks = [];
62
63 17
        $task = $this->tasks->get($name);
64
65 15
        if ($this->hooksEnabled) {
66 15
            $tasks = array_merge(array_map([$this, 'doGetTasks'], $task->getBefore()), $tasks);
67
        }
68
69 15
        if ($task instanceof GroupTask) {
70 5
            foreach ($task->getGroup() as $taskName) {
71 5
                $subTasks = $this->doGetTasks($taskName);
72 5
                foreach ($subTasks as $subTask) {
73 5
                    $subTask->addSelector($task->getSelector());
74 5
                    $tasks[] = $subTask;
75
                }
76
            }
77
        } else {
78 15
            $tasks[] = $task;
79
        }
80
81 15
        if ($this->hooksEnabled) {
82 15
            $tasks = array_merge($tasks, array_map([$this, 'doGetTasks'], $task->getAfter()));
83
        }
84
85 15
        return array_flatten($tasks);
86
    }
87
88
    public function getHooksEnabled()
89
    {
90
        return $this->hooksEnabled;
91
    }
92
93 12
    public function setHooksEnabled($hooksEnabled): void
94
    {
95 12
        $this->hooksEnabled = $hooksEnabled;
96 12
    }
97
98
    public function getStartFrom()
99
    {
100
        return $this->startFrom;
101
    }
102
103
    public function setStartFrom(string $startFrom): void
104
    {
105
        $this->startFrom = $startFrom;
106
    }
107
}
108