FetchApplicationOutput::setCommand()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @author stev leibelt <[email protected]>
4
 * @since 2015-07-11 
5
 */
6
7
namespace NetBazzlineZfCliGenerator\Service\ProcessPipe\Transformer;
8
9
10
use Net\Bazzline\Component\Command\Command;
11
use Net\Bazzline\Component\ProcessPipe\ExecutableException;
12
use Net\Bazzline\Component\ProcessPipe\ExecutableInterface;
13
14
class FetchApplicationOutput implements ExecutableInterface
15
{
16
    /** @var Command */
17
    private $command;
18
19
    /**
20
     * @param Command $command
21
     */
22
    public function setCommand(Command $command)
23
    {
24
        $this->command = $command;
25
    }
26
27
    /**
28
     * @param mixed $input
29
     * @return mixed
30
     * @throws ExecutableException
31
     */
32
    public function execute($input = null)
33
    {
34
        if (!is_string($input)) {
35
            throw new ExecutableException(
36
                'input must be a string'
37
            );
38
        }
39
40
        if (!file_exists($input)) {
41
            throw new ExecutableException(
42
                'file "' . $input . '" does not exist'
43
            );
44
        }
45
46
        $command = $this->command;
47
        //no command validation because of the fact that the zf2 application
48
        //  is setting an exit code greater 0 since noting was executed
49
        $output =  $command->execute('/usr/bin/env php ' . $input, false);
50
51
        return $output;
52
    }
53
}