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   A

Complexity

Total Complexity 21

Size/Duplication

Total Lines 109
Duplicated Lines 16.51 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 18
loc 109
ccs 0
cts 82
cp 0
rs 10
c 0
b 0
f 0
wmc 21
lcom 1
cbo 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A startTask() 0 7 2
A endTask() 0 22 5
A endOnHost() 0 6 2
C renderException() 18 51 11

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\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