Passed
Push — master ( abce15...80de3b )
by Gaetano
10:06
created

ProcessBuilder::getProcess()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 38
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 22
nc 5
nop 0
dl 0
loc 38
rs 9.2568
c 0
b 0
f 0
1
<?php
2
3
namespace Kaliop\eZMigrationBundle\Core\Process;
4
5
use Symfony\Component\Process\Exception\LogicException;
6
use Symfony\Component\Process\ProcessBuilder as BaseProcessBuilder;
7
8
/**
9
 * All we want is to make the ProcessBuilder return an eZMigrationBundle Process.
10
 * Since all the members of the original ProcessBuilder are private, this turns out to be more complex that simply
11
 * overriding the getProcess() method
12
 */
13
class ProcessBuilder extends BaseProcessBuilder
14
{
15
    /**
16
     * Creates a Process instance and returns it.
17
     *
18
     * @return Process
19
     *
20
     * @throws LogicException In case no arguments have been provided
21
     */
22
    public function getProcess()
23
    {
24
        /** @var array $this_prefix */
25
        $this_prefix = \Closure::bind(function(ProcessBuilder $builder){return $builder->prefix;}, null, $this);
0 ignored issues
show
Bug introduced by
The property prefix is declared private in Symfony\Component\Process\ProcessBuilder and cannot be accessed from this context.
Loading history...
26
        /** @var array $this_arguments */
27
        $this_arguments = \Closure::bind(function(ProcessBuilder $builder){return $builder->arguments;}, null, $this);
0 ignored issues
show
Bug introduced by
The property arguments is declared private in Symfony\Component\Process\ProcessBuilder and cannot be accessed from this context.
Loading history...
28
        /** @var array $this_options */
29
        $this_options = \Closure::bind(function(ProcessBuilder $builder){return $builder->options;}, null, $this);
0 ignored issues
show
Bug introduced by
The property options is declared private in Symfony\Component\Process\ProcessBuilder and cannot be accessed from this context.
Loading history...
30
        $this_inheritEnv = \Closure::bind(function(ProcessBuilder $builder){return $builder->inheritEnv;}, null, $this);
0 ignored issues
show
Bug introduced by
The property inheritEnv is declared private in Symfony\Component\Process\ProcessBuilder and cannot be accessed from this context.
Loading history...
31
        $this_env = \Closure::bind(function(ProcessBuilder $builder){return $builder->env;}, null, $this);
0 ignored issues
show
Bug introduced by
The property env is declared private in Symfony\Component\Process\ProcessBuilder and cannot be accessed from this context.
Loading history...
32
        $this_cwd = \Closure::bind(function(ProcessBuilder $builder){return $builder->cwd;}, null, $this);
0 ignored issues
show
Bug introduced by
The property cwd is declared private in Symfony\Component\Process\ProcessBuilder and cannot be accessed from this context.
Loading history...
33
        $this_input = \Closure::bind(function(ProcessBuilder $builder){return $builder->input;}, null, $this);
0 ignored issues
show
Bug introduced by
The property input is declared private in Symfony\Component\Process\ProcessBuilder and cannot be accessed from this context.
Loading history...
34
        $this_timeout = \Closure::bind(function(ProcessBuilder $builder){return $builder->timeout;}, null, $this);
0 ignored issues
show
Bug introduced by
The property timeout is declared private in Symfony\Component\Process\ProcessBuilder and cannot be accessed from this context.
Loading history...
35
        $this_outputDisabled = \Closure::bind(function(ProcessBuilder $builder){return $builder->outputDisabled;}, null, $this);
0 ignored issues
show
Bug introduced by
The property outputDisabled is declared private in Symfony\Component\Process\ProcessBuilder and cannot be accessed from this context.
Loading history...
36
37
        if (0 === count($this_prefix) && 0 === count($this_arguments)) {
38
            throw new LogicException('You must add() command arguments before calling getProcess().');
39
        }
40
41
        $options = $this_options;
42
43
        $arguments = array_merge($this_prefix, $this_arguments);
44
        $script = implode(' ', array_map(array(__NAMESPACE__.'\\ProcessUtils', 'escapeArgument'), $arguments));
45
46
        if ($this_inheritEnv) {
0 ignored issues
show
introduced by
$this_inheritEnv is of type Closure, thus it always evaluated to true.
Loading history...
47
            // include $_ENV for BC purposes
48
            $env = array_replace($_ENV, $_SERVER, $this_env);
0 ignored issues
show
Bug introduced by
$this_env of type Closure is incompatible with the type array|null expected by parameter $array2 of array_replace(). ( Ignorable by Annotation )

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

48
            $env = array_replace($_ENV, $_SERVER, /** @scrutinizer ignore-type */ $this_env);
Loading history...
49
        } else {
50
            $env = $this_env;
51
        }
52
53
        $process = new Process($script, $this_cwd, $env, $this_input, $this_timeout, $options);
0 ignored issues
show
Bug introduced by
$this_input of type Closure is incompatible with the type null|string expected by parameter $input of Kaliop\eZMigrationBundle...\Process::__construct(). ( Ignorable by Annotation )

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

53
        $process = new Process($script, $this_cwd, $env, /** @scrutinizer ignore-type */ $this_input, $this_timeout, $options);
Loading history...
Bug introduced by
$this_timeout of type Closure is incompatible with the type double|integer|null expected by parameter $timeout of Kaliop\eZMigrationBundle...\Process::__construct(). ( Ignorable by Annotation )

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

53
        $process = new Process($script, $this_cwd, $env, $this_input, /** @scrutinizer ignore-type */ $this_timeout, $options);
Loading history...
Bug introduced by
$this_cwd of type Closure is incompatible with the type null|string expected by parameter $cwd of Kaliop\eZMigrationBundle...\Process::__construct(). ( Ignorable by Annotation )

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

53
        $process = new Process($script, /** @scrutinizer ignore-type */ $this_cwd, $env, $this_input, $this_timeout, $options);
Loading history...
54
55
        if ($this_outputDisabled) {
0 ignored issues
show
introduced by
$this_outputDisabled is of type Closure, thus it always evaluated to true.
Loading history...
56
            $process->disableOutput();
57
        }
58
59
        return $process;
60
    }
61
}
62