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.

Printer   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Test Coverage

Coverage 92.31%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
dl 0
loc 76
c 1
b 0
f 0
rs 10
ccs 24
cts 26
cp 0.9231
wmc 11

6 Methods

Rating   Name   Duplication   Size   Complexity  
A writeln() 0 16 3
A filterOutput() 0 3 1
A __construct() 0 3 1
A command() 0 5 2
A printBuffer() 0 4 2
A callback() 0 5 2
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;
0 ignored issues
show
introduced by
The function Deployer\hostTag was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
15
16
class Printer
17
{
18
    private $output;
19
20 14
    public function __construct(OutputInterface $output)
21
    {
22 14
        $this->output = $output;
23 14
    }
24
25 10
    public function command(Host $host, string $command)
26
    {
27
        // -v for run command
28 10
        if ($this->output->isVerbose()) {
29 6
            $this->output->writeln("[{$host->getTag()}] <fg=green;options=bold>run</> $command");
30
        }
31 10
    }
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 10
    public function callback(Host $host)
40
    {
41
        return function ($type, $buffer) use ($host) {
42 9
            if ($this->output->isVerbose()) {
43 5
                $this->printBuffer($type, $host, $buffer);
44
            }
45 10
        };
46
    }
47
48
    /**
49
     * @param string $type Process::OUT or Process::ERR
50
     * @param Host $host
51
     * @param string $buffer
52
     */
53 5
    public function printBuffer(string $type, Host $host, string $buffer)
54
    {
55 5
        foreach (explode("\n", rtrim($buffer)) as $line) {
56 5
            $this->writeln($type, $host, $line);
57
        }
58 5
    }
59
60
    /**
61
     * @param string $type Process::OUT or Process::ERR
62
     * @param Host $host
63
     * @param string $line
64
     */
65 5
    public function writeln(string $type, Host $host, string $line)
66
    {
67 5
        $line = self::filterOutput($line);
68
69
        // Omit empty lines
70 5
        if (empty($line)) {
71
            return;
72
        }
73
74 5
        if ($type === Process::ERR) {
75
            $line = "[{$host->getTag()}] <fg=red>err</> $line";
76
        } else {
77 5
            $line = "[{$host->getTag()}] $line";
78
        }
79
80 5
        $this->output->writeln($line);
81 5
    }
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 9
    public static function filterOutput($output)
90
    {
91 9
        return preg_replace('/\[exit_code:(.*?)]/', '', $output);
92
    }
93
}
94