Completed
Pull Request — master (#132)
by
unknown
06:43 queued 04:56
created

ProcessBuilderFactory   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getBinary() 0 4 1
A create() 0 8 2
A useBinary() 0 10 3
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 Alchemy\Zippy\Exception\InvalidArgumentException;
15
16
class ProcessBuilderFactory implements ProcessBuilderFactoryInterface
17
{
18
    /**
19
     * The binary path
20
     *
21
     * @var string
22
     */
23
    protected $binary;
24
25
    /**
26
     * Constructor
27
     *
28
     * @param string $binary The path to the binary
29
     *
30
     * @throws InvalidArgumentException In case binary path is invalid
31
     */
32
    public function __construct($binary)
33
    {
34
        $this->useBinary($binary);
35
    }
36
37
    /**
38
     * @inheritdoc
39
     */
40
    public function getBinary()
41
    {
42
        return $this->binary;
43
    }
44
45
    /**
46
     * @inheritdoc
47
     */
48
    public function useBinary($binary)
49
    {
50
        if ('\\' !== DIRECTORY_SEPARATOR && !is_executable($binary)) {
51
            throw new InvalidArgumentException(sprintf('`%s` is not an executable binary', $binary));
52
        }
53
54
        $this->binary = $binary;
55
56
        return $this;
57
    }
58
59
    /**
60
     * @inheritdoc
61
     */
62
    public function create()
63
    {
64
        if (null === $this->binary) {
65
            throw new InvalidArgumentException('No binary set');
66
        }
67
68
        return ProcessBuilder::create(array($this->binary));
69
    }
70
}
71