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.
Completed
Push — master ( 4ae790...236d40 )
by TJ
02:47
created

CommandTasks   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 104
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 3
dl 0
loc 104
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setOutput() 0 6 1
A addTask() 0 6 1
A runTasks() 0 19 5
A getResults() 0 4 1
A hasFailedTasks() 0 4 1
A doNotThrowOnError() 0 6 1
1
<?php
2
3
namespace Honeybadger\HoneybadgerLaravel;
4
5
use Illuminate\Support\Collection;
6
use Illuminate\Console\OutputStyle;
7
use Honeybadger\HoneybadgerLaravel\Exceptions\TaskFailed;
8
9
class CommandTasks
10
{
11
    /**
12
     * @var \Illuminate\Console\OutputStyle
13
     */
14
    protected $output;
15
16
    /**
17
     * @var array
18
     */
19
    protected $results = [];
20
21
    /**
22
     * @var array
23
     */
24
    protected $tasks = [];
25
26
    /**
27
     * @var bool
28
     */
29
    protected $throwOnError = true;
30
31
    /**
32
     * Set command output.
33
     *
34
     * @param  \Illuminate\Console\OutputStyle  $output
35
     * @return self
36
     */
37
    public function setOutput(OutputStyle $output) : self
38
    {
39
        $this->output = $output;
40
41
        return $this;
42
    }
43
44
    /**
45
     * Add task with result to the stack.
46
     *
47
     * @param  string  $name
48
     * @param  callable  $task
49
     * @return self
50
     */
51
    public function addTask(string $name, callable $task) : self
52
    {
53
        $this->tasks[$name] = $task;
54
55
        return $this;
56
    }
57
58
    /**
59
     * Send tasks to the command output.
60
     *
61
     * @return void
62
     *
63
     * @throws \Honeybadger\HoneybadgerLaravel\TaskFailed
64
     */
65
    public function runTasks() : void
66
    {
67
        Collection::make($this->tasks)->each(function ($task, $description) {
68
            $result = $task();
69
70
            if ($this->output) {
71
                $this->output->writeLn(vsprintf('%s: %s', [
72
                    $description,
73
                    $result ? '<fg=green>✔</>' : '<fg=red>✘</>',
74
                ]));
75
            }
76
77
            $this->results[$description] = $result;
78
79
            if (! $result && $this->throwOnError) {
80
                throw new TaskFailed(sprintf('%s failed, please review output and try again.', $description));
81
            }
82
        });
83
    }
84
85
    /**
86
     * Get all task results.
87
     *
88
     * @return array
89
     */
90
    public function getResults() : array
91
    {
92
        return $this->results;
93
    }
94
95
    /**
96
     * @return bool
97
     */
98
    public function hasFailedTasks() : bool
99
    {
100
        return in_array(false, $this->results);
101
    }
102
103
    /**
104
     * @return self
105
     */
106
    public function doNotThrowOnError() : self
107
    {
108
        $this->throwOnError = false;
109
110
        return $this;
111
    }
112
}
113