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 ( c51706...f968f3 )
by Anton
01:54
created

ProcessOutputPrinter   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 87
ccs 0
cts 30
cp 0
rs 10
c 0
b 0
f 0
wmc 12
lcom 1
cbo 2

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A callback() 0 8 2
A command() 0 8 2
B writeln() 0 29 6
A filterOutput() 0 4 1
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\Utility;
9
10
use Deployer\Logger\Logger;
11
use Symfony\Component\Console\Output\OutputInterface;
12
use Symfony\Component\Process\Process;
13
14
class ProcessOutputPrinter
15
{
16
    /**
17
     * @var OutputInterface
18
     */
19
    private $output;
20
21
    /**
22
     * @var Logger
23
     */
24
    private $logger;
25
26
    public function __construct(OutputInterface $output, Logger $logger)
27
    {
28
        $this->output = $output;
29
        $this->logger = $logger;
30
    }
31
32
    /**
33
     * Returns a callable for use with the symfony Process->run($callable) method.
34
     *
35
     * @return callable A function expecting a int $type (e.g. Process::OUT or Process::ERR) and string $buffer parameters.
36
     */
37
    public function callback(string $hostname)
38
    {
39
        return function ($type, $buffer) use ($hostname) {
40
            foreach (explode("\n", rtrim($buffer)) as $line) {
41
                $this->writeln($type, $hostname, $line);
42
            }
43
        };
44
    }
45
46
    public function command(string $hostname, string $command)
47
    {
48
        $this->logger->log("[$hostname] > $command");
49
50
        if ($this->output->isVeryVerbose()) {
51
            $this->output->writeln("[$hostname] <fg=cyan>></fg=cyan> $command");
52
        }
53
    }
54
55
    /**
56
     * @param int $type Process::OUT or Process::ERR
57
     * @param string $hostname for debugging
58
     * @param string $line to print
59
     */
60
    public function writeln($type, $hostname, $line)
61
    {
62
        $line = $this->filterOutput($line);
63
64
        // Omit empty lines
65
        if (empty($line)) {
66
            return;
67
        }
68
69
        if ($type === Process::ERR) {
70
            $this->logger->log("[$hostname] < [error] $line");
71
        } else {
72
            $this->logger->log("[$hostname] < $line");
73
        }
74
75
        if ($this->output->isDecorated()) {
76
            if ($type === Process::ERR) {
77
                $line = "[$hostname] \033[0;31m<\e[0m $line";
78
            } else {
79
                $line = "[$hostname] \033[0;90m< $line\033[0m";
80
            }
81
        } else {
82
            $line = "[$hostname] < $line";
83
        }
84
85
        if ($this->output->isDebug()) {
86
            $this->output->writeln($line, OutputInterface::OUTPUT_RAW);
87
        }
88
    }
89
90
    /**
91
     * This filtering used only in Ssh\Client, but for simplify putted here.
92
     *
93
     * @param string $output
94
     * @return string
95
     */
96
    public function filterOutput($output)
97
    {
98
        return preg_replace('/\[exit_code:(.*?)\]/', '', $output);
99
    }
100
}
101