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.
Passed
Push — master ( b3cd52...71bd8a )
by Anton
02:19
created

ScriptManager   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 54
Duplicated Lines 11.11 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 78.26%

Importance

Changes 0
Metric Value
dl 6
loc 54
ccs 18
cts 23
cp 0.7826
rs 10
c 0
b 0
f 0
wmc 9
lcom 1
cbo 3

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B getTasks() 6 28 6
A getHooksEnabled() 0 4 1
A setHooksEnabled() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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 function Deployer\Support\array_flatten;
11
12
class ScriptManager
13
{
14
    private $tasks;
15
    private $hooksEnabled = true;
16
17 5
    public function __construct(TaskCollection $tasks)
18
    {
19 5
        $this->tasks = $tasks;
20 5
    }
21
22
    /**
23
     * Return tasks to run.
24
     *
25
     * @return Task[]
26
     */
27 5
    public function getTasks(string $name)
28
    {
29 5
        $tasks = [];
30
31 5
        $task = $this->tasks->get($name);
32
33 3 View Code Duplication
        if ($this->hooksEnabled) {
34 3
            $tasks = array_merge(array_map([$this, 'getTasks'], $task->getBefore()), $tasks);
35
        }
36
37 3
        if ($task instanceof GroupTask) {
38 1
            foreach ($task->getGroup() as $taskName) {
39 1
                $subTasks = $this->getTasks($taskName);
40 1
                foreach ($subTasks as $subTask) {
41 1
                    $subTask->addSelector($task->getSelector());
42 1
                    $tasks[] = $subTask;
43
                }
44
            }
45
        } else {
46 3
            $tasks[] = $task;
47
        }
48
49 3 View Code Duplication
        if ($this->hooksEnabled) {
50 3
            $tasks = array_merge($tasks, array_map([$this, 'getTasks'], $task->getAfter()));
51
        }
52
53 3
        return array_flatten($tasks);
54
    }
55
56
    public function getHooksEnabled()
57
    {
58
        return $this->hooksEnabled;
59
    }
60
61
    public function setHooksEnabled($hooksEnabled): void
62
    {
63
        $this->hooksEnabled = $hooksEnabled;
64
    }
65
}
66