Completed
Push — master ( df58f2...bfcb35 )
by Andreas
03:05
created

ProcessFactory::createProcess()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
1
<?php
2
/**
3
 * Process factory.
4
 *
5
 * @copyright 2014-2018 Institute of Legal Medicine, Medical University of Innsbruck
6
 * @author Andreas Erhard <[email protected]>
7
 * @author Nikola Vrlazic <[email protected]>
8
 * @license LGPL-3.0-only
9
 * @link http://www.gerichtsmedizin.at/
10
 *
11
 * @package pdftk
12
 */
13
14
namespace Gmi\Toolkit\Pdftk\Util;
15
16
use Symfony\Component\Process\Process;
17
18
/**
19
 * Factory class for creating Symfony process instances.
20
 *
21
 * @see https://symfony.com/doc/2.8/components/process.html
22
 */
23
class ProcessFactory
24
{
25
    /**
26
     * Creates a process from command line.
27
     *
28
     * @param string $commandLine
29
     *
30
     * @return Process
31
     */
32 11
    public function createProcess($commandLine)
33
    {
34
        // support old (Symfony 2.7 to 4.1) and new (Symfony 4.2+) syntax to build Symfony Process instances.
35 11
        $process = $this->useNewSyntax() ? Process::fromShellCommandline($commandLine) : new Process($commandLine);
1 ignored issue
show
Bug introduced by
$commandLine of type string is incompatible with the type array expected by parameter $command of Symfony\Component\Process\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

35
        $process = $this->useNewSyntax() ? Process::fromShellCommandline($commandLine) : new Process(/** @scrutinizer ignore-type */ $commandLine);
Loading history...
36
37 11
        return $process;
38
    }
39
40
    /**
41
     * Returns whether the new syntax to build Symfony Process instances from a command line should be used.
42
     *
43
     * @see https://github.com/symfony/symfony/pull/27821
44
     *
45
     * @return bool
46
     */
47 11
    private function useNewSyntax()
48
    {
49 11
        return method_exists(Process::class, 'fromShellCommandline');
50
    }
51
}
52