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 ( f968f3...d9c744 )
by Anton
02:00
created

ProcessRunner   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 47
Duplicated Lines 10.64 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 92.86%

Importance

Changes 0
Metric Value
dl 5
loc 47
ccs 13
cts 14
cp 0.9286
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A run() 5 23 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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\Deployer;
11
use Symfony\Component\Process\Exception\ProcessFailedException;
12
use Symfony\Component\Process\Process;
13
14
class ProcessRunner
15
{
16
    /**
17
     * @var ProcessOutputPrinter
18
     */
19
    private $pop;
20
21 10
    public function __construct(ProcessOutputPrinter $pop)
22
    {
23 10
        $this->pop = $pop;
24 10
    }
25
26
    /**
27
     * Runs a command, consider deployer global configs (timeout,...)
28
     *
29
     * @param string $hostname
30
     * @param string $command
31
     * @param array $config
32
     *
33
     * @return string
34
     *
35
     * @throws ProcessFailedException When the process does not return a 0 exit code.
36
     */
37 10
    public function run($hostname, string $command, array $config = [])
38
    {
39
        $defaults = [
40 10
            'timeout' => Deployer::getDefault('default_timeout', 300),
41
            'tty' => false,
42
        ];
43 10
        $config = array_merge($defaults, $config);
44
45 10
        $this->pop->command($hostname, $command);
46
47 10 View Code Duplication
        if (method_exists('Symfony\Component\Process\Process', 'fromShellCommandline')) {
48 10
            $process = Process::fromShellCommandline($command);
49
        } else {
50
            $process = new Process($command);
51
        }
52
53
        $process
54 10
            ->setTimeout($config['timeout'])
55 10
            ->setTty($config['tty'])
56 10
            ->mustRun($this->pop->callback($hostname));
57
58 10
        return $process->getOutput();
59
    }
60
}
61