Completed
Push — master ( 68693d...b79797 )
by Adam
12:25
created

ProcessHelper   A

Coupling/Cohesion

Components 1
Dependencies 2

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 39
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A createProcess() 0 8 1
A createProcessBuilder() 0 11 1
1
<?php
2
/*
3
 * WellCommerce Open-Source E-Commerce Platform
4
 *
5
 * This file is part of the WellCommerce package.
6
 *
7
 * (c) Adam Piotrowski <[email protected]>
8
 *
9
 * For the full copyright and license information,
10
 * please view the LICENSE file that was distributed with this source code.
11
 */
12
13
namespace WellCommerce\Bundle\CoreBundle\Helper\Process;
14
15
use Symfony\Component\Process\Process;
16
use Symfony\Component\Process\ProcessBuilder;
17
18
/**
19
 * Class ProcessHelper
20
 *
21
 * @author  Adam Piotrowski <[email protected]>
22
 */
23
final class ProcessHelper implements ProcessHelperInterface
24
{
25
    /**
26
     * @var string
27
     */
28
    protected $phpBinaryPath;
29
    
30
    /**
31
     * @var string
32
     */
33
    protected $cwd;
34
    
35
    public function __construct(string $phpBinaryPath, string $cwd)
36
    {
37
        $this->phpBinaryPath = $phpBinaryPath;
38
        $this->cwd           = $cwd;
39
    }
40
    
41
    public function createProcess(array $arguments, int $timeout = 720): Process
42
    {
43
        $command = $this->createProcessBuilder($arguments, $timeout)->getProcess()->getCommandLine();
44
        $process = new Process($command, $this->cwd);
45
        $process->setTimeout($timeout);
46
        
47
        return $process;
48
    }
49
    
50
    public function createProcessBuilder(array $arguments, $timeout = 720): ProcessBuilder
51
    {
52
        $builder = new ProcessBuilder();
53
        $builder->setPrefix($this->phpBinaryPath);
54
        $builder->setWorkingDirectory($this->cwd);
55
        $builder->setArguments($arguments);
56
        $builder->setTimeout($timeout);
57
        $builder->inheritEnvironmentVariables(true);
58
        
59
        return $builder;
60
    }
61
}
62
63