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 ( 05bc19...aa0e82 )
by Anton
02:15
created

Messenger::printException()   C

Complexity

Conditions 11
Paths 8

Size

Total Lines 51

Duplication

Lines 18
Ratio 35.29 %

Code Coverage

Tests 0
CRAP Score 132

Importance

Changes 0
Metric Value
cc 11
nc 8
nop 2
dl 18
loc 51
rs 6.9224
c 0
b 0
f 0
ccs 0
cts 46
cp 0
crap 132

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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\Exception;
11
use Deployer\Exception\RunException;
12
use Deployer\Host\Host;
13
use Deployer\Task\Task;
14
use Symfony\Component\Console\Input\Input;
15
use Symfony\Component\Console\Output\Output;
16
use Throwable;
17
18
class Messenger
19
{
20
    private $input;
21
    private $output;
22
23
    /**
24
     * @var int|double
25
     */
26
    private $startTime;
27
28
    public function __construct(Input $input, Output $output)
29
    {
30
        $this->input = $input;
31
        $this->output = $output;
32
    }
33
34
    public function startTask(Task $task)
35
    {
36
        $this->startTime = round(microtime(true) * 1000);
37
        if (!$task->isShallow()) {
38
            $this->output->writeln("<fg=cyan;options=bold>task</> {$task->getName()}");
39
        }
40
    }
41
42
    /*
43
     * Print task was ok.
44
     */
45
    public function endTask(Task $task)
46
    {
47
        if ($task->isShallow()) {
48
            return;
49
        }
50
51
        $endTime = round(microtime(true) * 1000);
52
        $millis = $endTime - $this->startTime;
53
        $seconds = floor($millis / 1000);
54
        $millis = $millis - $seconds * 1000;
55
        $taskTime = ($seconds > 0 ? "{$seconds}s " : "") . "{$millis}ms";
56
57
        if ($this->output->isVeryVerbose()) {
58
            $this->output->writeln("<fg=yellow;options=bold>done</> {$task->getName()} $taskTime");
59
        }
60
61
        if (!empty($this->input->getOption('profile'))) {
62
            $line = sprintf("%s\t%s\n", $task->getName(), $taskTime);
63
            file_put_contents($this->input->getOption('profile'), $line, FILE_APPEND);
64
65
        }
66
    }
67
68
    public function endOnHost(Host $host)
69
    {
70
        if ($this->output->isVeryVerbose()) {
71
            $this->output->writeln("[{$host->tag()}] <info>ok</info>");
72
        }
73
    }
74
75
    public function renderException(Throwable $exception, Host $host)
76
    {
77
        if ($exception instanceof RunException) {
78
79
            $message = "";
80
            $message .= "[{$host->tag()}] <fg=white;bg=red> error </> <comment>in {$exception->getFilename()} on line {$exception->getLineNumber()}:</>\n";
81
            if ($this->output->getVerbosity() === Output::VERBOSITY_NORMAL) {
82
                $message .= "[{$host->tag()}] <fg=green;options=bold>run</> {$exception->getCommand()}\n";
83 View Code Duplication
                foreach (explode("\n", $exception->getErrorOutput()) as $line) {
84
                    $line = trim($line);
85
                    if ($line !== "") {
86
                        $message .= "[{$host->tag()}] <fg=red>err</> $line\n";
87
                    }
88
                }
89 View Code Duplication
                foreach (explode("\n", $exception->getOutput()) as $line) {
90
                    $line = trim($line);
91
                    if ($line !== "") {
92
                        $message .= "[{$host->tag()}] $line\n";
93
                    }
94
                }
95
            }
96
            $message .= "[{$host->tag()}] <fg=red>exit code</> {$exception->getExitCode()} ({$exception->getExitCodeText()})\n";
97
            $this->output->write($message);
98
99
        } else {
100
101
            $message = "";
102
            $class = get_class($exception);
103
            $file = basename($exception->getFile());
104
            $line = $exception->getLine();
105
            if ($exception instanceof Exception) {
106
                $file = $exception->getFilename();
107
                $line = $exception->getLineNumber();
108
            }
109
            $message .= "[{$host->tag()}] <fg=white;bg=red> $class </> <comment>in $file on line $line:</>\n";
110
            $message .= "[{$host->tag()}]\n";
111 View Code Duplication
            foreach (explode("\n", $exception->getMessage()) as $line) {
112
                $line = trim($line);
113
                if ($line !== "") {
114
                    $message .= "[{$host->tag()}]   <comment>$line</comment>\n";
115
                }
116
            }
117
            $message .= "[{$host->tag()}]\n";
118
            $this->output->write($message);
119
120
        }
121
122
        if ($exception->getPrevious()) {
123
            $this->renderException($exception->getPrevious(), $host);
124
        }
125
    }
126
}
127