ProcessFactory::useNewSyntax()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * Process factory.
4
 *
5
 * @copyright 2014-2022 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
    const PROCESS_DEFAULT_TIMEOUT = 300;
26
27
    /**
28
     * Creates a process from command line.
29
     *
30
     * @param string $commandLine Command line of the process
31
     * @param int    $timeout     Symfony process timeout
32
     *
33
     * @return Process
34
     */
35 12
    public function createProcess($commandLine, $timeout = self::PROCESS_DEFAULT_TIMEOUT)
36
    {
37
        // support old (Symfony 2.7 to 4.1) and new (Symfony 4.2+) syntax to build Symfony Process instances.
38 12
        $process = $this->useNewSyntax() ? Process::fromShellCommandline($commandLine) : new Process($commandLine);
39 12
        $process->setTimeout($timeout);
40
41 12
        return $process;
42
    }
43
44
    /**
45
     * Returns whether the new syntax to build Symfony Process instances from a command line should be used.
46
     *
47
     * @see https://github.com/symfony/symfony/pull/27821
48
     *
49
     * @return bool
50
     */
51 12
    private function useNewSyntax()
52
    {
53 12
        return method_exists(Process::class, 'fromShellCommandline');
54
    }
55
}
56