ProcessBuilder::create()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of Zippy.
5
 *
6
 * (c) Alchemy <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Alchemy\Zippy\ProcessBuilder;
13
14
use Symfony\Component\Process\Process;
15
16
class ProcessBuilder implements ProcessBuilderInterface
17
{
18
    /**
19
     * The command to run and its arguments listed as separate entries
20
     *
21
     * @var array
22
     */
23
    private $command;
24
25
    /**
26
     * The working directory or null to use the working dir of the current PHP process
27
     *
28
     * @var string|null
29
     */
30
    private $cwd;
31
32
    /**
33
     * ProcessBuilder constructor.
34
     * @param array $command
35
     */
36
    public function __construct($command)
37
    {
38
        $this->command = $command;
39
        $this->cwd = null;
40
    }
41
42
    /**
43
     * Creates a Process instance and returns it
44
     *
45
     * @return Process
46
     */
47
    public function getProcess()
48
    {
49
        $process =  new Process($this->command, $this->cwd);
50
        $process->setTimeout(null);
51
52
        return $process;
53
    }
54
55
    /**
56
     * @inheritdoc
57
     */
58
    public function add($argument)
59
    {
60
        $this->command = array_merge($this->command, array($argument));
61
62
        return $this;
63
    }
64
65
    /**
66
     * @inheritdoc
67
     */
68
    public function setWorkingDirectory($directory)
69
    {
70
        $this->cwd = $directory;
71
72
        return $this;
73
    }
74
75
    /**
76
     * The command to run or a binary path and its arguments listed as separate entries
77
     *
78
     * @param array $command
79
     *
80
     * @return static
81
     */
82
    public static function create(array $command)
83
    {
84
        return new static($command);
85
    }
86
87
}
88