AbstractCliSpawningTask   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 3
dl 0
loc 31
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A runProcess() 0 19 3
1
<?php
2
3
/**
4
 * This file is part of tenside/core.
5
 *
6
 * (c) Christian Schiffler <[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
 * This project is provided in good faith and hope to be usable by anyone.
12
 *
13
 * @package    tenside/core
14
 * @author     Christian Schiffler <[email protected]>
15
 * @copyright  2015 Christian Schiffler <[email protected]>
16
 * @license    https://github.com/tenside/core/blob/master/LICENSE MIT
17
 * @link       https://github.com/tenside/core
18
 * @filesource
19
 */
20
21
namespace Tenside\Core\Task;
22
23
use Symfony\Component\Process\Exception\ProcessFailedException;
24
use Symfony\Component\Process\Process;
25
26
/**
27
 * This class is an abstract base for running a cli command.
28
 */
29
abstract class AbstractCliSpawningTask extends Task
30
{
31
    /**
32
     * Run a process and throw exception if it failed.
33
     *
34
     * @param Process $process The process to run.
35
     *
36
     * @return void
37
     *
38
     * @throws ProcessFailedException When the process returned a non zero result.
39
     */
40
    protected function runProcess(Process $process)
41
    {
42
        $ioHandler = $this->getIO();
43
        $process->run(
44
            function ($pipe, $content) use ($ioHandler) {
45
                if (Process::ERR === $pipe) {
46
                    $ioHandler->writeError($content, false);
47
                    // @codingStandardsIgnoreStart
48
                    return;
49
                    // @codingStandardsIgnoreEnd
50
                }
51
                $ioHandler->write($content, false);
52
            }
53
        );
54
55
        if (0 !== $process->getExitCode()) {
56
            throw new ProcessFailedException($process);
57
        }
58
    }
59
}
60