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 ( 09a43c...4f79d5 )
by Anton
03:00
created

Printer   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 78
Duplicated Lines 21.79 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 92.31%

Importance

Changes 0
Metric Value
dl 17
loc 78
ccs 24
cts 26
cp 0.9231
rs 10
c 0
b 0
f 0
wmc 11
lcom 1
cbo 2

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A filterOutput() 0 4 1
A command() 0 7 2
A callback() 0 8 2
A printBuffer() 0 6 2
A writeln() 17 17 3

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\Component\ProcessRunner;
9
10
use Deployer\Host\Host;
11
use Deployer\Logger\Logger;
12
use Symfony\Component\Console\Output\OutputInterface;
13
use Symfony\Component\Process\Process;
14
use function Deployer\hostTag;
15
16
class Printer
17
{
18
    private $output;
19
20 6
    public function __construct(OutputInterface $output)
21
    {
22 6
        $this->output = $output;
23 6
    }
24
25 5
    public function command(Host $host, string $command)
26
    {
27
        // -v for run command
28 5
        if ($this->output->isVerbose()) {
29 2
            $this->output->writeln("[{$host->tag()}] <fg=green;options=bold>run</> $command");
30
        }
31 5
    }
32
33
    /**
34
     * Returns a callable for use with the symfony Process->run($callable) method.
35
     *
36
     * @param Host $host
37
     * @return callable A function expecting a int $type (e.g. Process::OUT or Process::ERR) and string $buffer parameters.
38
     */
39 5
    public function callback(Host $host)
40
    {
41
        return function ($type, $buffer) use ($host) {
42 5
            if ($this->output->isVerbose()) {
43 2
                $this->printBuffer($type, $host, $buffer);
44
            }
45 5
        };
46
    }
47
48
    /**
49
     * @param string $type Process::OUT or Process::ERR
50
     * @param Host $host
51
     * @param string $buffer
52
     */
53 2
    public function printBuffer(string $type, Host $host, string $buffer)
54
    {
55 2
        foreach (explode("\n", rtrim($buffer)) as $line) {
56 2
            $this->writeln($type, $host, $line);
57
        }
58 2
    }
59
60
    /**
61
     * @param string $type Process::OUT or Process::ERR
62
     * @param Host $host
63
     * @param string $line
64
     */
65 2 View Code Duplication
    public function writeln(string $type, Host $host, string $line)
66
    {
67 2
        $line = self::filterOutput($line);
68
69
        // Omit empty lines
70 2
        if (empty($line)) {
71
            return;
72
        }
73
74 2
        if ($type === Process::ERR) {
75
            $line = "[{$host->tag()}] <fg=red>err</> $line";
76
        } else {
77 2
            $line = "[{$host->tag()}] $line";
78
        }
79
80 2
        $this->output->writeln($line);
81 2
    }
82
83
    /**
84
     * This filtering used only in Ssh\Client, but for simplify putted here.
85
     *
86
     * @param string $output
87
     * @return string
88
     */
89 5
    public static function filterOutput($output)
90
    {
91 5
        return preg_replace('/\[exit_code:(.*?)]/', '', $output);
92
    }
93
}
94