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 ( 85b4d8...848934 )
by Anton
02:45
created

ProcessRunner::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/* (c) Anton Medvedev <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Deployer\ProcessRunner;
12
13
use Deployer\Exception\RunException;
14
use Deployer\Exception\TimeoutException;
15
use Deployer\Host\Host;
16
use Deployer\Logger\Logger;
17
use Deployer\ProcessRunner\Printer;
18
use Symfony\Component\Process\Exception\ProcessFailedException;
19
use Symfony\Component\Process\Exception\ProcessTimedOutException;
20
use Symfony\Component\Process\Process;
21
22
class ProcessRunner
23
{
24
    private Printer $pop;
25
    private Logger $logger;
26
27
    public function __construct(Printer $pop, Logger $logger)
28
    {
29
        $this->pop = $pop;
30
        $this->logger = $logger;
31
    }
32
33
    public function run(Host $host, string $command, array $config = []): string
34
    {
35
        $defaults = [
36
            'timeout' => $host->get('default_timeout', 300),
37
            'idle_timeout' => null,
38
            'cwd' => getenv('DEPLOYER_ROOT') !== false ? getenv('DEPLOYER_ROOT') : (defined('DEPLOYER_DEPLOY_FILE') ? dirname(DEPLOYER_DEPLOY_FILE) : null),
0 ignored issues
show
Bug introduced by
The constant Deployer\ProcessRunner\DEPLOYER_DEPLOY_FILE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
39
            'real_time_output' => false,
40
            'shell' => 'bash -s',
41
        ];
42
        $config = array_merge($defaults, $config);
43
44
        $this->pop->command($host, 'run', $command);
45
46
        $terminalOutput = $this->pop->callback($host, $config['real_time_output']);
47
        $callback = function ($type, $buffer) use ($host, $terminalOutput) {
48
            $this->logger->printBuffer($host, $type, $buffer);
49
            $terminalOutput($type, $buffer);
50
        };
51
52
        $command = str_replace('%secret%', $config['secret'] ?? '', $command);
53
        $command = str_replace('%sudo_pass%', $config['sudo_pass'] ?? '', $command);
54
55
        $process = Process::fromShellCommandline($config['shell'])
56
            ->setInput($command)
57
            ->setTimeout($config['timeout'])
58
            ->setIdleTimeout($config['idle_timeout']);
59
60
        if ($config['cwd'] !== null) {
61
            $process->setWorkingDirectory($config['cwd']);
62
        }
63
64
        try {
65
            $process->mustRun($callback);
66
            return $process->getOutput();
67
        } catch (ProcessFailedException $exception) {
68
            throw new RunException(
69
                $host,
70
                $command,
71
                $process->getExitCode(),
0 ignored issues
show
Bug introduced by
It seems like $process->getExitCode() can also be of type null; however, parameter $exitCode of Deployer\Exception\RunException::__construct() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

71
                /** @scrutinizer ignore-type */ $process->getExitCode(),
Loading history...
72
                $process->getOutput(),
73
                $process->getErrorOutput(),
74
            );
75
        } catch (ProcessTimedOutException $exception) {
76
            throw new TimeoutException(
77
                $command,
78
                $exception->getExceededTimeout(),
79
            );
80
        }
81
    }
82
}
83