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

ProcessBuilderFactory::getBinary()   A

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 0
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