Completed
Pull Request — master (#39)
by Marc
02:27 queued 01:14
created

ProcessBuilder   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 63
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getProcess() 0 8 1
A setTimeout() 0 5 1
A __construct() 0 5 1
A setArguments() 0 5 1
1
<?php
2
declare(strict_types=1);
3
/*
4
 * This file is part of the asm\php-ansible package.
5
 *
6
 * (c) Marc Aschmann <[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 Asm\Ansible\Process;
13
14
use Symfony\Component\Process\Process;
15
16
/**
17
 * Wrapper for symfony process component to allow for command option/argument collection before execute
18
 *
19
 * @package Asm\Ansible\Process
20
 * @author Marc Aschmann <[email protected]>
21
 */
22
class ProcessBuilder implements ProcessBuilderInterface
23
{
24
    /**
25
     * @var array
26
     */
27
    private $arguments;
28
29
    /**
30
     * @var int
31
     */
32
    private $timeout;
33
34
    /**
35
     * @var string
36
     */
37
    private $path;
38
39
    /**
40
     * ProcessBuilder constructor.
41
     *
42
     * @param string $prefix
43
     * @param string $path
44
     */
45
    public function __construct(string $prefix, string $path)
46
    {
47
        $this->arguments = [$prefix];
48
        $this->path = $path;
49
        $this->timeout = 900;
50
    }
51
52
    /**
53
     * @param array $arguments arguments for process generation
54
     * @return ProcessBuilderInterface
55
     */
56
    public function setArguments(array $arguments): ProcessBuilderInterface
57
    {
58
        $this->arguments = $arguments;
59
60
        return $this;
61
    }
62
63
    /**
64
     * @param int $timeout
65
     * @return ProcessBuilderInterface
66
     */
67
    public function setTimeout(int $timeout): ProcessBuilderInterface
68
    {
69
        $this->timeout = $timeout;
70
71
        return $this;
72
    }
73
74
    /**
75
     * @return Process
76
     */
77
    public function getProcess(): Process
78
    {
79
        return (
80
            new Process(
81
                $this->arguments,
82
                $this->path
83
            )
84
        )->setTimeout($this->timeout);
85
    }
86
}
87