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.
Test Failed
Pull Request — master (#1904)
by Anton
02:21
created

Status::taskException()   B

Complexity

Conditions 9
Paths 5

Size

Total Lines 40

Duplication

Lines 18
Ratio 45 %

Code Coverage

Tests 0
CRAP Score 90

Importance

Changes 0
Metric Value
cc 9
nc 5
nop 2
dl 18
loc 40
ccs 0
cts 39
cp 0
crap 90
rs 7.7244
c 0
b 0
f 0
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\Executor;
9
10
use Deployer\Exception\RunException;
11
use Deployer\Host\Host;
12
use Deployer\Task\Task;
13
use Symfony\Component\Console\Output\Output;
14
use Throwable;
15
16
class Status
17
{
18
    private $output;
19
20
    /**
21
     * @var int|double
22
     */
23
    private $startTime;
24
25
    public function __construct(Output $output)
26
    {
27
        $this->output = $output;
28
    }
29
30
    public function startTask(Task $task)
31
    {
32
        $this->startTime = round(microtime(true) * 1000);
33
        if (!$task->isShallow()) {
34
            $this->output->writeln("<fg=cyan;options=bold>task</> {$task->getName()}");
35
        }
36
    }
37
38
    /*
39
     * Print task was ok.
40
     */
41
    public function endTask(Task $task)
42
    {
43
        if ($task->isShallow()) {
44
            return;
45
        }
46
47
        $endTime = round(microtime(true) * 1000);
48
        $millis = $endTime - $this->startTime;
49
        $seconds = floor($millis / 1000);
50
        $millis = $millis - $seconds * 1000;
51
        $taskTime = ($seconds > 0 ? "{$seconds}s " : "") . "{$millis}ms";
52
53
        if ($this->output->isVeryVerbose()) {
54
            $this->output->writeln("<fg=yellow;options=bold>done</> {$task->getName()} $taskTime");
55
        }
56
    }
57
58
    public function endOnHost(Host $host)
59
    {
60
        if ($this->output->isVeryVerbose()) {
61
            $this->output->writeln("[{$host->tag()}] <info>ok</info>");
62
        }
63
    }
64
65
    public function taskException(Throwable $exception, Host $host)
66
    {
67
        if ($exception instanceof RunException) {
68
            $message = "";
69
            $message .= "[{$host->tag()}] <fg=white;bg=red> error </> <comment>in {$exception->getFilename()} on line {$exception->getLineNumber()}:</comment>\n";
70
            if ($this->output->getVerbosity() === Output::VERBOSITY_NORMAL) {
71
                $message .= "[{$host->tag()}] <fg=green;options=bold>run</> {$exception->getCommand()}\n";
72 View Code Duplication
                foreach (explode("\n", $exception->getErrorOutput()) as $line) {
73
                    $line = trim($line);
74
                    if ($line !== "") {
75
                        $message .= "[{$host->tag()}] <fg=red>err</> $line\n";
76
                    }
77
                }
78 View Code Duplication
                foreach (explode("\n", $exception->getOutput()) as $line) {
79
                    $line = trim($line);
80
                    if ($line !== "") {
81
                        $message .= "[{$host->tag()}] $line\n";
82
                    }
83
                }
84
            }
85
            $message .= "[{$host->tag()}] <fg=red>exit code</> {$exception->getExitCode()} ({$exception->getExitCodeText()})\n";
86
            $this->output->write($message);
87
            return;
88
        }
89
90
        $message = "";
91
        $class = get_class($exception);
92
        $file = basename($exception->getFile());
93
        $line = $exception->getLine();
94
        $message .= "[{$host->tag()}] <fg=white;bg=red> $class </> <comment>in $file on line $line:</comment>\n";
95
        $message .= "[{$host->tag()}]\n";
96 View Code Duplication
        foreach (explode("\n", $exception->getMessage()) as $line) {
97
            $line = trim($line);
98
            if ($line !== "") {
99
                $message .= "[{$host->tag()}]   <comment>$line</comment>\n";
100
            }
101
        }
102
        $message .= "[{$host->tag()}]\n";
103
        $this->output->write($message);
104
    }
105
}
106