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
Push — master ( 444b11...55afa9 )
by Anton
18:50 queued 16:47
created

Messenger   A

Complexity

Total Complexity 24

Size/Duplication

Total Lines 115
Duplicated Lines 20.87 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 48.48%

Importance

Changes 0
Metric Value
dl 24
loc 115
ccs 32
cts 66
cp 0.4848
rs 10
c 0
b 0
f 0
wmc 24
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() 24 57 14

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 8
    public function __construct(Input $input, Output $output)
29
    {
30 8
        $this->input = $input;
31 8
        $this->output = $output;
32 8
    }
33
34 7
    public function startTask(Task $task)
35
    {
36 7
        $this->startTime = round(microtime(true) * 1000);
37 7
        if (!$task->isShallow()) {
38 7
            $this->output->writeln("<fg=cyan;options=bold>task</> {$task->getName()}");
39
        }
40 7
    }
41
42
    /*
43
     * Print task was ok.
44
     */
45 7
    public function endTask(Task $task)
46
    {
47 7
        if ($task->isShallow()) {
48 5
            return;
49
        }
50
51 7
        $endTime = round(microtime(true) * 1000);
52 7
        $millis = $endTime - $this->startTime;
53 7
        $seconds = floor($millis / 1000);
54 7
        $millis = $millis - $seconds * 1000;
55 7
        $taskTime = ($seconds > 0 ? "{$seconds}s " : "") . "{$millis}ms";
56
57 7
        if ($this->output->isVeryVerbose()) {
58
            $this->output->writeln("<fg=yellow;options=bold>done</> {$task->getName()} $taskTime");
59
        }
60
61 7
        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 7
    }
67
68 1
    public function endOnHost(Host $host)
69
    {
70 1
        if ($this->output->isVeryVerbose()) {
71
            $this->output->writeln("[{$host->tag()}] <info>ok</info>");
72
        }
73 1
    }
74
75 1
    public function renderException(Throwable $exception, Host $host)
76
    {
77 1
        if ($exception instanceof RunException) {
78
79 1
            $message = "";
80 1
            $message .= "[{$host->tag()}] <fg=white;bg=red> error </> <comment>in {$exception->getTaskFilename()} on line {$exception->getTaskLineNumber()}:</>\n";
81 1
            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 1
            $message .= "[{$host->tag()}] <fg=red>exit code</> {$exception->getExitCode()} ({$exception->getExitCodeText()})\n";
97 1
            $this->output->write($message);
98
99
        } else {
100
            $message = "";
101
            $class = get_class($exception);
102
            $file = basename($exception->getFile());
103
            $line = $exception->getLine();
104
            if ($exception instanceof Exception) {
105
                $file = $exception->getTaskFilename();
106
                $line = $exception->getTaskLineNumber();
107
            }
108
            $message .= "[{$host->tag()}] <fg=white;bg=red> $class </> <comment>in $file on line $line:</>\n";
109
            $message .= "[{$host->tag()}]\n";
110 View Code Duplication
            foreach (explode("\n", $exception->getMessage()) as $line) {
111
                $line = trim($line);
112
                if ($line !== "") {
113
                    $message .= "[{$host->tag()}]   <comment>$line</comment>\n";
114
                }
115
            }
116
            $message .= "[{$host->tag()}]\n";
117
            if ($this->output->isDebug()) {
118 View Code Duplication
                foreach (explode("\n", $exception->getTraceAsString()) as $line) {
119
                    $line = trim($line);
120
                    if ($line !== "") {
121
                        $message .= "[{$host->tag()}] $line\n";
122
                    }
123
                }
124
            }
125
            $this->output->write($message);
126
        }
127
128 1
        if ($exception->getPrevious()) {
129
            $this->renderException($exception->getPrevious(), $host);
130
        }
131 1
    }
132
}
133