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
Pull Request — master (#2062)
by
unknown
02:12
created

ProcessRunner   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 96.3%

Importance

Changes 0
Metric Value
dl 0
loc 62
ccs 26
cts 27
cp 0.963
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A run() 0 40 4
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 8
    public function __construct(Printer $pop, Logger $logger)
24
    {
25 8
        $this->pop = $pop;
26 8
        $this->logger = $logger;
27 8
    }
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 8
    public function run(Host $host, string $command, array $config = []): string
40
    {
41
        $defaults = [
42 8
            'timeout' => $host->get('default_timeout', 300),
43
            'idle_timeout' => null,
44 8
            'cwd' => defined('DEPLOYER_ROOT') ? DEPLOYER_ROOT : null,
45
            'tty' => false,
46
        ];
47 8
        $config = array_merge($defaults, $config);
48
49 8
        $this->pop->command($host, $command);
50
51 8
        $terminalOutput = $this->pop->callback($host);
52
        $callback = function ($type, $buffer) use ($host, $terminalOutput) {
53 8
            $this->logger->printBuffer($host, $type, $buffer);
54 8
            $terminalOutput($type, $buffer);
55 8
        };
56
57 8
        $process = Process::fromShellCommandline(str_replace('%secret%', $config['secret'] ?? '', $command))
58 8
            ->setTimeout($config['timeout'])
59 8
            ->setIdleTimeout($config['idle_timeout'])
60 8
            ->setTty($config['tty']);
61
62 8
        if ($config['cwd'] !== null) {
63
            $process->setWorkingDirectory($config['cwd']);
64
        }
65
66
        try {
67 8
            $process->mustRun($callback);
68 8
            return $process->getOutput();
69 1
        } catch (ProcessFailedException $exception) {
70 1
            throw new RunException(
71 1
                $host,
72
                $command,
73 1
                $process->getExitCode(),
74 1
                $process->getOutput(),
75 1
                $process->getErrorOutput()
76
            );
77
        }
78
    }
79
}
80