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 ( e51949...763526 )
by Anton
01:57
created

ProcessRunner   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 73.91%

Importance

Changes 0
Metric Value
dl 0
loc 56
rs 10
c 0
b 0
f 0
ccs 17
cts 23
cp 0.7391
wmc 3
lcom 1
cbo 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A run() 0 34 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\Deployer;
11
use Deployer\Component\ProcessRunner\Printer;
12
use Deployer\Exception\RunException;
13
use Deployer\Host\Host;
14
use Deployer\Logger\Logger;
15
use Symfony\Component\Process\Exception\ProcessFailedException;
16
use Symfony\Component\Process\Process;
17
18
class ProcessRunner
19
{
20
    private $pop;
21
    private $logger;
22
23 1
    public function __construct(Printer $pop, Logger $logger)
24
    {
25 1
        $this->pop = $pop;
26 1
        $this->logger = $logger;
27 1
    }
28
29
    /**
30
     * Runs a command, consider deployer global configs (timeout,...)
31
     *
32
     * @param Host $host
33
     * @param string $command
34
     * @param array $config
35
     *
36
     * @return string
37
     *
38
     */
39 1
    public function run(Host $host, string $command, array $config = []): string
40
    {
41
        $defaults = [
42 1
            'timeout' => $host->get('default_timeout', 300),
43
            'tty' => false,
44
        ];
45 1
        $config = array_merge($defaults, $config);
46
47 1
        $this->pop->command($host, $command);
48
49 1
        $terminalOutput = $this->pop->callback($host);
50
        $callback = function ($type, $buffer) use ($host, $terminalOutput) {
51 1
            $this->logger->printBuffer($host, $type, $buffer);
52 1
            $terminalOutput($type, $buffer);
53 1
        };
54
55
        try {
56 1
            $process = Process::fromShellCommandline(str_replace('%secret%', $config['secret'] ?? '', $command));
57
            $process
58 1
                ->setTimeout($config['timeout'])
59 1
                ->setTty($config['tty'])
60 1
                ->mustRun($callback);
61
62 1
            return $process->getOutput();
63
        } catch (ProcessFailedException $exception) {
64
            throw new RunException(
65
                $host->alias(),
66
                $command,
67
                $process->getExitCode(),
68
                $process->getOutput(),
69
                $process->getErrorOutput()
70
            );
71
        }
72
    }
73
}
74