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 ( 4e243a...9b019b )
by Anton
02:15
created

Status   A

Complexity

Total Complexity 18

Size/Duplication

Total Lines 90
Duplicated Lines 20 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 18
loc 90
ccs 0
cts 70
cp 0
rs 10
c 0
b 0
f 0
wmc 18
lcom 1
cbo 4

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A startTask() 0 7 2
A endTask() 0 16 4
A endOnHost() 0 6 2
B taskException() 18 40 9

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