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.
Completed
Push — master ( 35ced9...058dc2 )
by Anton
07:38
created

Rsync::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 2
nc 1
nop 2
dl 0
loc 4
c 0
b 0
f 0
cc 1
rs 10
ccs 0
cts 4
cp 0
crap 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\Utility;
9
10
use Deployer\Component\ProcessRunner\Printer;
11
use Deployer\Exception\RunException;
12
use Deployer\Host\Host;
13
use Symfony\Component\Console\Helper\ProgressBar;
14
use Symfony\Component\Console\Output\OutputInterface;
15
use Symfony\Component\Process\Exception\ProcessFailedException;
16
use Symfony\Component\Process\Process;
17
18
class Rsync
19
{
20
    private $pop;
21
    private $output;
22
23
    public function __construct(Printer $pop, OutputInterface $output)
24
    {
25
        $this->pop = $pop;
26
        $this->output = $output;
27
    }
28
29
    /*
30
     * Start rsync process.
31
     */
32
    public function call(Host $host, string $source, string $destination, array $config = [])
33
    {
34
        $defaults = [
35
            'timeout' => null,
36
            'options' => [],
37
        ];
38
        $config = array_merge($defaults, $config);
39
40
        $options = $config['options'] ?? [];
41
42
        $sshArguments = $host->getSshArguments()->getCliArguments();
43
        if ($sshArguments !== '') {
44
            $options[] = "-e 'ssh $sshArguments'";
45
        }
46
47
        if ($host->has("become")) {
48
            $options[] = "--rsync-path='sudo -H -u {$host->get('become')} rsync'";
49
        }
50
51
        $command = sprintf(
52
            "rsync -azP %s %s %s",
53
            implode(' ', $options),
54
            escapeshellarg($source),
55
            escapeshellarg($destination)
56
        );
57
        $this->pop->command($host, $command);
58
59
        $progressBar = null;
60
        if ($this->output->getVerbosity() === OutputInterface::VERBOSITY_NORMAL) {
61
            $progressBar = new ProgressBar($this->output);
62
            $progressBar->setBarCharacter('<info>≡</info>');
63
            $progressBar->setProgressCharacter('>');
64
            $progressBar->setEmptyBarCharacter('-');
65
        }
66
67
        $callback = function ($type, $buffer) use ($host, $progressBar) {
68
            if ($progressBar) {
69
                foreach (explode("\n", $buffer) as $line) {
70
                    if (preg_match('/(to-chk|to-check)=(\d+?)\/(\d+)/', $line, $match)) {
71
                        $max = intval($match[3]);
72
                        $step = $max - intval($match[2]);
73
                        $progressBar->setMaxSteps($max);
74
                        $progressBar->setFormat("[{$host->getTag()}] %current%/%max% [%bar%] %percent:3s%% %elapsed:6s%/%estimated:-6s%");
75
                        $progressBar->setProgress($step);
76
                    }
77
                }
78
                return;
79
            }
80
            if ($this->output->isVerbose()) {
81
                $this->pop->printBuffer($type, $host, $buffer);
82
            }
83
        };
84
85
        $process = Process::fromShellCommandline($command)
86
            ->setTimeout($config['timeout']);
87
        try {
88
            $process->mustRun($callback);
89
        } catch (ProcessFailedException $exception) {
90
            throw new RunException(
91
                $host,
92
                $command,
93
                $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

93
                /** @scrutinizer ignore-type */ $process->getExitCode(),
Loading history...
94
                $process->getOutput(),
95
                $process->getErrorOutput()
96
            );
97
        } finally {
98
            if ($progressBar) {
99
                $progressBar->clear();
100
            }
101
        }
102
    }
103
}
104